import Foundation

struct ContentLabel {

    var icon: PageIcon

    var value: String
}

extension ContentLabel: Equatable {

    static func == (lhs: ContentLabel, rhs: ContentLabel) -> Bool {
        lhs.icon == rhs.icon && lhs.value == rhs.value
    }
}

extension ContentLabel: Identifiable {

    var id: String {
        icon.rawValue + value
    }
}

extension ContentLabel {

    var data: Data {
        .init(icon: icon.rawValue, value: value)
    }

    init?(context: LoadingContext, data: Data) {
        guard let icon = PageIcon(rawValue: data.icon) else {
            context.error("Unknown label icon '\(data.icon)'")
            return nil
        }
        self.init(icon: icon, value: data.value)
    }

    struct Data: Codable, Equatable {
        let icon: String
        let value: String
    }
}
