import Foundation

struct MeasurementDailyCount {
    
    var dateIndex: Int
    
    var count: Int
    
    var date: Date {
        .init(dateIndex: dateIndex)
    }
}

extension MeasurementDailyCount: Codable {
    
    init(from decoder: Decoder) throws {
        var container = try decoder.unkeyedContainer()
        self.dateIndex = try container.decode(Int.self)
        self.count = try container.decode(Int.self)
    }
    
    func encode(to encoder: Encoder) throws {
        var container = encoder.unkeyedContainer()
        try container.encode(dateIndex)
        try container.encode(count)
    }
}

extension MeasurementDailyCount: Comparable {
    
    static func < (lhs: MeasurementDailyCount, rhs: MeasurementDailyCount) -> Bool {
        lhs.dateIndex < rhs.dateIndex
    }
    
    static func == (lhs: MeasurementDailyCount, rhs: MeasurementDailyCount) -> Bool {
        lhs.dateIndex == rhs.dateIndex
    }
}

extension MeasurementDailyCount: Identifiable {
    
    var id: Int {
        dateIndex
    }
}
