//
//  KMAdvertisementTablePresenter.swift
//  KMAdvertisement
//
//  Created by lizhe on 2022/11/28.
//

class KMAdvertisementTableViewPresenter: NSObject {
    lazy var modelData: [KMAdvertisementModel.Section] = []
    var view: AnyObject?
    fileprivate weak var delegate: KMAdvertisementTableViewPresenterDelegate?
}

extension KMAdvertisementTableViewPresenter: KMAdvertisementTableViewPresenterProtocol {
    /**
     初始化presenter
     */
    func initPresenter(view:AnyObject, data: KMAdvertisementModel) {
        self.delegate = view as? any KMAdvertisementTableViewPresenterDelegate
        
        self.modelData.removeAll()
        let array = data.content
        
        for item in array {
            self.modelData.append(item)
        }
        self.delegate?.showData(presenter: self, data: self.modelData)
    }
    
    func cleanAll() {
        self.modelData.removeAll()
        self.delegate?.showData(presenter: self, data: self.modelData)
    }
    
    func free() {
        view = nil
        delegate = nil
    }
}


protocol KMAdvertisementTableViewPresenterDelegate: AnyObject {
    /**
     @abstract 回调，返回处理后的数据<KMBatchProcessingViewModel>类型
     @param presenter
     @param data 返回数据
     */
    func showData(presenter: KMAdvertisementTableViewPresenter, data: Array<KMAdvertisementModel.Section>)
}

protocol KMAdvertisementTableViewPresenterProtocol {
    /**
     @abstract 绑定视图与数据
     @param view 视图
     @param data 资源 <KMBatchProcessingViewModel>类型
     */
    func initPresenter(view:AnyObject, data: KMAdvertisementModel)
    /**
     @abstract 解除绑定
     */
    func free()
}
