<?php

namespace App\Exports;

use App\Models\pricelist;
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 ExportPriceList implements FromCollection, WithHeadings,WithStyles ,ShouldAutoSize{
    function __construct($slug) {
        $this->slug = $slug;
    }

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

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

    public function headings() :array{
        //return ['car_model', 'colour_type', 'transmission', 'ex_showroom_price', 'tcs', 'statutory_charges', 'registration_individual_charges', 'registration_corporate_charges', 'insurance', 'fasttag', 'on_road_individual_charges', 'on_road_corporate_charges', 'extended_warranty', 'accessories_kit', 'total_road_individual_charges', 'total_road_corporate_charges'];
        return ['Price List Name','CSD','RTO Type','Car Model','Fuel Type','Car Variant','RTO Custom Handling Charges','Tone Selection','Branch Name','Transmission','BASIC','CSD Selling Price','LS Order Amount','GST','GST AMOUNT','CESS','CESS AMOUNT','Ex Showroom Price','TCS','Registration Individual charges','Registration corporate charges','Insurance','Fasttag','On Road individual charges','On Road Corporate charges','RSA MASTER','Extended Warranty','My Convinience Program','Final On Road Price Individual','Final on Road Price Corporate','Other Details 1','Other Details 2','Detail Value'];
    }

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