//
//  MapAmapTheStyleOfAnnection.swift
//  map_amap_ios
//
//  Created by 诺诺诺的言 on 2025/7/22.
//

import Foundation


protocol MapMarkerSupportType: Codable {
    var rawValue: Int { get }

    var supportSelected: Bool { get }

    func imageName(selected: Bool) -> String

    var size: CGSize { get }
    
    var isMapAchorPoint : Bool {get}
    
    var isTracePopup : Bool {get}
    
    var markType : MapMarkerSupportType {get}
    
    var isTracePassing : Bool {get}
}

// 创建一个全局辅助类来处理解码/编码
struct MarkerTypeFactory {
    static func markerType(from rawValue: Int) -> any MapMarkerSupportType {
        // 根据应用包类型选择正确的枚举类型
        switch currentPackage {
        case .traceLocation1:
            return MarkerType(rawValue: rawValue) ?? MarkerType.mine
        // 如果有更多包类型，可以在这里添加
        }
    }
}

// 为MapMarkerSupportType添加Codable实现
extension MapMarkerSupportType {
    // 编码为整数
    func encode(to encoder: Encoder) throws {
        var container = encoder.singleValueContainer()
        try container.encode(rawValue)
    }
}

// 第一个包的标记类型
enum MarkerType: Int, MapMarkerSupportType {
    case mine = 1
    case friend = 2
    case traceStart = 3
    case traceEndFriend = 4
    case traceEndMine = 5
    case tracePopup = 6 //popup气泡样式
    case tracePassing = 7 //轨迹途径点样式
    case trackError = 8 //轨迹错误点样式
    
    var supportSelected: Bool {
        return self == .mine
    }
    func imageName(selected: Bool) -> String {
        let prefixName: String = currentPackage.rawValue
        let imageBaseName: String = switch self {
            case .mine:
                "mine"
            case .friend:
                "friend"
            case .traceStart:
                "traceStart"
            case .traceEndFriend:
                "traceEndFriend"
            case .traceEndMine:
                "traceEndMine"
            case .tracePopup:
                "tracePopup"
            case .tracePassing:
                "tracePassing"
            case .trackError:
                "trackError"
        }
        return "\(prefixName)_\(imageBaseName)" + ((selected && supportSelected) ? "_selected" : "")
    }

    var size: CGSize {
        switch self {
            case .traceStart:
                return CGSize(width: 22, height: 36)
            default:
                return CGSize(width: 44, height: 52)
        }
    }
    
    var isMapAchorPoint : Bool {
        return self == .tracePassing || self == .trackError
    }
    
    var markType: MapMarkerSupportType {
        return self
    }
    
    var isTracePassing : Bool {
        return self == .tracePassing
    }
    
    var isTracePopup : Bool {
        return self == .tracePopup
    }
}
