<?php

declare(strict_types=1);

namespace Maestro\Core\Modules\HourRegistration\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class HourInvoicingByClientRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user() !== null
            && ($this->user()->can('hours.invoicing.read') || $this->user()->can('hours.admin'));
    }

    /**
     * @return array<string, mixed>
     */
    public function rules(): array
    {
        return [
            'customer_id' => ['required', 'integer', 'exists:customers,id'],
            'from' => ['required', 'date'],
            'to' => ['required', 'date', 'after_or_equal:from'],
        ];
    }
}
