<?php

namespace App\Exports;

use App\Models\ComplaintCell;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;

class ComplaintsExport implements FromCollection, WithHeadings
{

    protected $from;
    protected $to;


    public function __construct($from, $to)
    {
        $this->from = $from;
        $this->to = $to;
    }


    public function collection()
    {
        return ComplaintCell::whereBetween('created_at', [
                $this->from . ' 00:00:00',
                $this->to . ' 23:59:59'
            ])
            ->select(
                'id',
                'complainant_name',
                'contact_number',
                'district',
                'address',
                'complaint',
                'complaint_against_type',
                'complaint_against_name',
                'created_at'
            )
            ->get();
    }


    public function headings(): array
    {
        return [
            'ID',
            'Complainant Name',
            'Contact Number',
            'District',
            'Address',
            'Complaint',
            'Complaint Against Type',
            'Complaint Against',
            'Date'
        ];
    }

}