<?php

namespace App\Modules\HR\Recruitment\Services;

use App\Modules\HR\Recruitment\DTOs\RecruitmentReportFilters;
use App\Modules\HR\Recruitment\Services\ReportBuilders\ApplicationsByStatusReportBuilder;
use App\Modules\HR\Recruitment\Services\ReportBuilders\CandidatePipelineReportBuilder;
use App\Modules\HR\Recruitment\Services\ReportBuilders\FunnelReportBuilder;
use App\Modules\HR\Recruitment\Services\ReportBuilders\HiringReportBuilder;
use App\Modules\HR\Recruitment\Services\ReportBuilders\InterviewResultsReportBuilder;
use App\Modules\HR\Recruitment\Services\ReportBuilders\OfferAcceptanceReportBuilder;
use App\Modules\HR\Recruitment\Services\ReportBuilders\OpenVacanciesReportBuilder;
use App\Modules\HR\Recruitment\Services\ReportBuilders\RecruitmentReportBuilder;
use App\Modules\HR\Recruitment\Services\ReportBuilders\SourceAnalysisReportBuilder;
use App\Modules\HR\Recruitment\Services\ReportBuilders\TimeToHireReportBuilder;
use App\Modules\HR\Recruitment\Support\RecruitmentReportType;
use InvalidArgumentException;

class RecruitmentReportRegistry
{
    /** @return array<string, class-string<RecruitmentReportBuilder>> */
    public function map(): array
    {
        return [
            RecruitmentReportType::FUNNEL => FunnelReportBuilder::class,
            RecruitmentReportType::OPEN_VACANCIES => OpenVacanciesReportBuilder::class,
            RecruitmentReportType::CANDIDATE_PIPELINE => CandidatePipelineReportBuilder::class,
            RecruitmentReportType::APPLICATIONS_BY_STATUS => ApplicationsByStatusReportBuilder::class,
            RecruitmentReportType::INTERVIEW_RESULTS => InterviewResultsReportBuilder::class,
            RecruitmentReportType::OFFER_ACCEPTANCE => OfferAcceptanceReportBuilder::class,
            RecruitmentReportType::HIRING => HiringReportBuilder::class,
            RecruitmentReportType::TIME_TO_HIRE => TimeToHireReportBuilder::class,
            RecruitmentReportType::SOURCE_ANALYSIS => SourceAnalysisReportBuilder::class,
        ];
    }

    public function builder(string $type): RecruitmentReportBuilder
    {
        $class = $this->map()[$type] ?? null;
        if ($class === null) {
            throw new InvalidArgumentException('Unknown recruitment report: '.$type);
        }

        return app($class);
    }

    /** @return array{title_key: string, columns: list<string>, rows: list, summary: array} */
    public function build(string $type, int $tenantId, RecruitmentReportFilters $filters): array
    {
        return $this->builder($type)->build($tenantId, $filters);
    }
}
