//
//  Peripheral.swift
//  MVM5G
//
//  Created by Matt Bruce on 4/13/22.
//  Copyright © 2022 Kyle. All rights reserved.
//

import Foundation
import CoreBluetooth

public struct PeripheralModel: CBUUIDIdentifiable, Codable, Equatable {
    var uuid: CBUUID

    enum CodingKeys: String, CodingKey {
        case uuid
    }

    public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        let _uuid = try typeContainer.decode(String.self, forKey: .uuid)
        uuid = CBUUID(string: _uuid)
    }
    
    public func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(uuid.uuidString, forKey: .uuid)
    }
    
    public static func == (lhs: PeripheralModel, rhs: PeripheralModel) -> Bool {
        return lhs.uuid == rhs.uuid
    }

}
