<?php

namespace App\Http\Requests\Admin;

use Illuminate\Foundation\Http\FormRequest;

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

    /**
     * @return array<string, mixed>
     */
    public function rules(): array
    {
        return [
            'name' => ['required', 'string', 'max:120'],
            'price' => ['required', 'numeric', 'min:0'],
            'daily_ai_limit' => ['required', 'integer', 'min:1', 'max:100000'],
            'monthly_ai_limit' => ['nullable', 'integer', 'min:0', 'max:10000000'],
            'features_json' => ['nullable', 'string', 'max:20000'],
            'status' => ['required', 'in:active,inactive'],
        ];
    }

    protected function prepareForValidation(): void
    {
        if ($this->input('monthly_ai_limit') === '' || $this->input('monthly_ai_limit') === null) {
            $this->merge(['monthly_ai_limit' => null]);
        }
    }
}
