<?php

declare(strict_types=1);

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class GenerateReportRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    /** @return array<string, array<int, mixed>> */
    public function rules(): array
    {
        return [
            'report_type' => ['required', Rule::in(['revenue', 'profit_loss', 'tax', 'aging', 'refund', 'subscription'])],
            'start_date' => ['nullable', 'date', 'required_unless:report_type,aging'],
            'end_date' => ['nullable', 'date', 'required_unless:report_type,aging', 'after_or_equal:start_date'],
            'service_type' => ['nullable', Rule::in(['vps', 'dedicated', 'hosting', 'mysql', 'game', 'backups'])],
            'format' => ['nullable', Rule::in(['pdf', 'csv', 'json'])],
        ];
    }

    /** @return array<string, string> */
    public function messages(): array
    {
        return [
            'report_type.required' => 'Please select a report type.',
            'report_type.in' => 'Invalid report type selected.',
            'start_date.required_unless' => 'Start date is required for this report type.',
            'end_date.required_unless' => 'End date is required for this report type.',
            'end_date.after_or_equal' => 'End date must be on or after the start date.',
            'service_type.in' => 'Invalid service type selected.',
            'format.in' => 'Export format must be pdf, csv, or json.',
        ];
    }
}
