<?php

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

class SelectForSale
{

    public function __construct(
        private SaleBySellerMonthlyReportShowBy $showBy
    ) {}

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

    public function __invoke($apply, $title)
    {
        $showByTypes = [
            SaleBySellerMonthlyReportShowBy::MONTH => fn($month, $year) => "`M` = $month AND `Y` = $year",
            SaleBySellerMonthlyReportShowBy::YEAR => fn($month, $year) => "`Y` = $year",
            SaleBySellerMonthlyReportShowBy::RANGE => fn($month, $year) => "1",
        ];
        return fn($month, $year, $admin) => [
            "$title " . self::MONTH_NAMES[$month - 1] . " $year $admin" =>
            "COUNT(IF(" . $showByTypes[$this->showBy->value()]($month, $year) . " AND `aux`.`Id_Admin` = $admin $apply, `aux`.`Id_BookingTour`, NULL))"
        ];
    }
}
