//
//  TSHomeDataModel.swift
//  TSLiveWallpaper
//
//  Created by 100Years on 2024/12/23.
//
import ObjectMapper


class TSHomeBannerDataSectionModel: TSBaseModel {
    
    var style:ImageDataStyple = .homeLiveList {
        didSet{
            for itemModel in itemModels {
                itemModel.style = style
            }
        }
    }
    
    var itemModels:[TSHomeBannerDataItemModel] = [TSHomeBannerDataItemModel]()
    
    override func mapping(map: ObjectMapper.Map) {
        style <- map["style"]
        itemModels <- map["itemModels"]
    }
}


extension TSHomeBannerDataSectionModel : CollectionViewSectionComponent{
    var sectionInset: UIEdgeInsets {
        return style.sectionInset
    }
    
    var lineSpacing: CGFloat {
        return style.lineSpacing
    }
    
    var itemSpacing: CGFloat {
        return style.itemSpacing
    }
    var headerComponent: CollectionViewReuseViewComponent? {
        nil
    }
    var cells: [CollectionViewCellComponent] {
        return itemModels
    }
}

//MARK: TSHomeBannerDataItemModel
class TSHomeBannerDataItemModel: TSBaseModel {
    
    var style:ImageDataStyple = .homeLiveList {
        didSet{
            for itemModel in items {
                itemModel.style = style
            }
        }
    }
    
    var type:String = ""
    var items:[TSImageDataItemModel] = [TSImageDataItemModel]()
    var vip:Bool = false
    override func mapping(map: ObjectMapper.Map) {
        type    <- map["type"]
        items   <- map["items"]
        vip     <- map["vip"]
        style    <- map["style"]
    }
    
}

extension TSHomeBannerDataItemModel : CollectionViewCellComponent {
    
    var cellClass: UICollectionViewCell.Type {
        style.cellClass
    }
    
    func cellSize(with attrubites: [String : Any]?) -> CGSize {
        style.cellSize
    }
}
