//
//  DiscountCell.swift
//  FoodPool
//
//  Created by Ayşe Nur Bakırcı on 11.08.2021.
//

import UIKit
import Extensions
import RestaurantAPI

class DiscountCell: UITableViewCell {
    
    static let reuseIdentifier: String = "discountCellID"
    
    //MARK: - Properties
    private let discountView = DiscountCollectionView()
    
    //MARK: - Initalization
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        contentView.backgroundColor = .white
        contentView.addSubview(discountView)
        discountView.fillSuperView()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func apply(model: Discount) {
        
        var urlList: [URL] = []
        
        model.results.forEach { imagePath in
            guard let url = BundleAPI.imageNameToURL(folderName: model.storageName, imageName: imagePath)
            else { return }
            urlList.append(url)
        }
        discountView.data.accept(urlList)
    }
}
