//
//  TSRandomWallpaperModel.swift
//  TSLiveWallpaper
//
//  Created by 100Years on 2024/12/23.
//

import ObjectMapper


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


extension TSRandomWallpaperDataSectionModel : 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
    }
}


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

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