<?php

namespace App\Exports;

use App\Models\ExtandWarranty;
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 ExportExtandWarranty implements FromCollection, WithHeadings,WithStyles ,ShouldAutoSize{
    
    protected $slug;

    
    public function __construct($slug) {
        $this->slug = $slug;
    }

    public function collection(){
        $model = new ExtandWarranty();
        $data = $model->export($this->slug);

        if($data == null){
            throw new \ErrorException('No data found');
        }else{
            return $data;
        }
    }

    public function headings() :array{
        return ['Car Model','Fule Type','Plan Name', 'Amount', 'Profit', 'GST %', 'GST Amount', 'Total Profit', 'Status'];
    }

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