<?php

namespace App\Http\Requests\Admin;

use App\Http\Requests\ApiFormRequest;
use Illuminate\Validation\Rule;

/** @see ReportJobStoreController */
final class ReportJobStoreRequest extends ApiFormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    /** @return array<string, array<int, mixed>> */
    public function rules(): array
    {
        return [
            'report_type' => ['required', 'string', Rule::in(self::reportTypes())],
            'export_format' => ['sometimes', 'string', Rule::in(['csv', 'xlsx'])],
            'parameters' => ['sometimes', 'array'],
            'parameters.date_from' => ['sometimes', 'nullable', 'date_format:Y-m-d'],
            'parameters.date_to' => ['sometimes', 'nullable', 'date_format:Y-m-d', 'after_or_equal:parameters.date_from'],
            'parameters.player_id' => ['sometimes', 'nullable', 'integer', 'min:1'],
            'parameters.play_code' => ['sometimes', 'nullable', 'string', 'max:32'],
            'parameters.operator_id' => ['sometimes', 'nullable', 'integer', 'min:1'],
            'parameters.draw_id' => ['sometimes', 'nullable', 'integer', 'min:1'],
            'parameters.draw_no' => ['sometimes', 'nullable', 'string', 'max:64'],
            'parameters.normalized_number' => ['sometimes', 'nullable', 'regex:/^[0-9]{4}$/'],
            'filter_json' => ['sometimes', 'array'],
            'filter_json.date_from' => ['sometimes', 'nullable', 'date_format:Y-m-d'],
            'filter_json.date_to' => ['sometimes', 'nullable', 'date_format:Y-m-d', 'after_or_equal:filter_json.date_from'],
            'filter_json.draw_id' => ['sometimes', 'nullable', 'integer', 'min:1'],
            'filter_json.draw_no' => ['sometimes', 'nullable', 'string', 'max:64'],
            'filter_json.normalized_number' => ['sometimes', 'nullable', 'regex:/^[0-9]{4}$/'],
        ];
    }

    /** @return list<string> */
    public static function reportTypes(): array
    {
        return [
            'draw_profit_summary',
            'daily_profit_summary',
            'player_win_loss',
            'wallet_transfer_report',
            'hot_number_risk_report',
            'play_dimension_report',
            'sold_out_number_report',
            'audit_operation_report',
            'wallet_txns_daily',
            'transfer_orders_daily',
        ];
    }
}
