//
//  Header.swift
//  MVMCoreUI
//
//  Created by Suresh, Kamlesh on 10/3/19.
//  Copyright © 2019 Suresh, Kamlesh. All rights reserved.
//


open class HeaderModel: ContainerModel {
    open var backgroundColor: Color?
    open var line: LineModel?
    
    private enum CodingKeys: String, CodingKey {
        case line
        case backgroundColor
    }
    
    /// Defaults to set
    open override func setDefaults() {
        if useHorizontalMargins == nil {
            useHorizontalMargins = true
        }
        if useVerticalMargins == nil {
            useVerticalMargins = true
        }
        if topPadding == nil {
            topPadding = PaddingDefaultVerticalSpacing
        }
        if bottomPadding == nil {
            bottomPadding = PaddingDefaultVerticalSpacing
        }
    }
    
    public override init() {
        super.init()
    }

    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)
        backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
    }
    
    open 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)
        try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
    }
}
