<?php

namespace App\Modules\Report\Booking\Domain\LeadBySellerMonthly;

class LeadBySellerMonthlySelect
{

    public function __construct(
        private LeadBySellerMonthlyReportShowBy $showBy
    ) {}

    public const MONTH_NAMES = ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'];

    public function __invoke($apply, $title)
    {
        $showByTypes = [
            LeadBySellerMonthlyReportShowBy::MONTH => fn($month, $year) => "`aux`.`m` = $month AND `aux`.`y` = $year",
            LeadBySellerMonthlyReportShowBy::YEAR => fn($month, $year) => "`aux`.`y` = $year"
        ];
        return fn($month, $year) => [
            "$title " . self::MONTH_NAMES[$month - 1] . " $year" =>
            "COUNT(IF(" . $showByTypes[$this->showBy->value()]($month, $year) . ", $apply, NULL))"
        ];
    }
}
