<?php

namespace App\Modules\HR\Recruitment\Repositories;

use App\Modules\HR\Recruitment\DTOs\RecruitmentReportFilters;
use Illuminate\Database\Eloquent\Builder;

final class RecruitmentReportFilterQuery
{
    public function applyDate(Builder $q, string $column, RecruitmentReportFilters $f): void
    {
        if ($f->dateFrom !== null) {
            $q->whereDate($column, '>=', $f->dateFrom);
        }
        if ($f->dateTo !== null) {
            $q->whereDate($column, '<=', $f->dateTo);
        }
    }

    public function applyRecruiter(Builder $q, RecruitmentReportFilters $f): void
    {
        if ($f->recruiterId !== null) {
            $q->where('created_by', $f->recruiterId);
        }
    }

    public function applyStatus(Builder $q, RecruitmentReportFilters $f): void
    {
        if ($f->status !== null) {
            $q->where('status', $f->status);
        }
    }

    public function applyVacancyScope(Builder $q, RecruitmentReportFilters $f, string $vacancyCol): void
    {
        if ($f->vacancyId !== null) {
            $q->where($vacancyCol, $f->vacancyId);
        }
        if ($f->departmentId !== null) {
            $q->whereHas('vacancy', fn (Builder $v) => $v->where('department_id', $f->departmentId));
        }
    }
}
