//
//  BGVideoImageMoleculeModel.swift
//  MVMCoreUI
//
//  Created by Scott Pfeil on 1/26/21.
//  Copyright © 2021 Verizon Wireless. All rights reserved.
//

import UIKit

open class BGVideoImageMoleculeModel: BGImageMoleculeModel {
    open override class var identifier: String {
        return "bgVideoImageContainer"
    }
    
    public var video: VideoModel

    public override var children: [MoleculeModelProtocol] {
        return [video, molecule]
    }
    
    private enum CodingKeys: String, CodingKey {
        case video
    }

    public init(_ video: VideoModel, image: ImageViewModel, molecule: MoleculeModelProtocol) {
        self.video = video
        super.init(image, molecule: molecule)
    }

    required public init(from decoder: Decoder) throws {
        let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
        video = try typeContainer.decode(VideoModel.self, forKey:.video)
        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(video, forKey: .video)
    }
}
