<?php
namespace App\Modules\HR\Reports\Data;

use App\Modules\HR\Core\Models\Employee;
use Carbon\Carbon;

class EmployeeRecruitmentReport
{
    public function getData($filters)
    {
        $query = Employee::with([
            'branch',
            'department',
            'designation',
            'gender',
            'maritalStatus',
            'bloodGroup',
            'grade',
            'employmentType',
            'payrollGroup',
            'identificationType'
        ]);

        // Branch filter
        if (!empty($filters['branch_id'])) {
            $query->where('branch_id', $filters['branch_id']);
        }

        // Department filter
        if (!empty($filters['department_id'])) {
            $query->where('department_id', $filters['department_id']);
        }

        // Join Date filter
        if (!empty($filters['from_date']) && !empty($filters['to_date'])) {

            $from = Carbon::parse($filters['from_date'])->startOfDay();
            $to   = Carbon::parse($filters['to_date'])->endOfDay();

            $query->whereBetween('date_of_joining', [$from, $to]);
        }

        $employees = $query->get();


        return [
            'employees' => $employees
        ];
    }
}
