//
//  ListStarRatingModel.swift
//  MVMCoreUI
//
//  Created by Lekshmi S on 22/10/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//

open class ListStarRatingModel: ListItemModel, MoleculeModelProtocol {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    public static var identifier: String = "listStarRating"
    public var stars: StarsModel
    public var reviewsCount: LabelModel
    
    //--------------------------------------------------
    // MARK: - Initializer
    //--------------------------------------------------
    public init(stars: StarsModel, reviewsCount: LabelModel) {
        self.stars = stars
        self.reviewsCount = reviewsCount
        super.init()
    }
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    private enum CodingKeys: String, CodingKey {
        case moleculeName
        case stars
        case reviewsCount
    }
    
    //--------------------------------------------------
    // MARK: - Codec
    //--------------------------------------------------
    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        stars = try typeContainer.decode(StarsModel.self, forKey: .stars)
        reviewsCount = try typeContainer.decode(LabelModel.self, forKey: .reviewsCount)
        try super.init(from: decoder)
    }
    
    open override func encode(to encoder: Encoder) throws {
        try super.encode(to: encoder)
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(moleculeName, forKey: .moleculeName)
        try container.encode(stars, forKey: .stars)
        try container.encode(reviewsCount, forKey: .reviewsCount)
    }
}
