<?php

namespace App\Exports;

use App\Models\offer;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithStyles;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;

class ExportOffersDiscount implements FromCollection, WithHeadings, WithStyles, ShouldAutoSize{
    function __construct($slug) {
        $this->slug = $slug;
    }

    public function collection(){
        $user = new offer();
        $data = $user->export($this->slug);
        
        if($data == null){
            throw new \ErrorException('No Data Found!');
        }else{
            return $data;
        }
    }

    public function headings() :array{
        return ['Title','Start Date','End Date','Offer Type' ,'Amount','KIA Share / Company Contribution','Branch', 'Car Model', 'Fuel Type' ,'Car Variant' , 'Car Vin number' ,'Remark', 'Status'];
    }

    public function styles(Worksheet $sheet){
        return [1 => ['font' => ['bold' => true]]];
    }
}