//
//  MoleculeSectionHeaderModel.swift
//  MVMCoreUI
//
//  Created by Scott Pfeil on 10/2/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//


@objcMembers open class MoleculeSectionHeaderModel: MoleculeContainerModel, SectionListHeaderFooterModel {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    public class override var identifier: String { "sectionHeader" }
    public var line: LineModel?
    
    //--------------------------------------------------
    // MARK: - Keys
    //--------------------------------------------------
    
    private enum CodingKeys: String, CodingKey {
        case line
        case backgroundColor
    }
    
    //--------------------------------------------------
    // MARK: - Methods
    //--------------------------------------------------
    
    /// Defaults to set
    public override func setDefaults() {
        if useHorizontalMargins == nil {
            useHorizontalMargins = true
        }
        if useVerticalMargins == nil {
            useVerticalMargins = true
        }
        if topPadding == nil {
            topPadding = PaddingDefaultVerticalSpacing3
        }
        if bottomPadding == nil {
            bottomPadding = PaddingDefaultVerticalSpacing3
        }
        if line == nil {
            line = LineModel(type: .thin)
        }
    }
    
    //--------------------------------------------------
    // MARK: - Codec
    //--------------------------------------------------
    
    required public init(from decoder: Decoder) throws {
        try super.init(from: decoder)
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line)
    }
    
    public override func encode(to encoder: Encoder) throws {
        try super.encode(to: encoder)
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(line, forKey: .line)
    }
}
