<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class StoreAccountRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'name' => 'required|string|max:100',
            'type' => 'required|in:cash,bank,credit_card,savings,investment,e_wallet,loan,other',
            'currency_id' => 'required|exists:currencies,id',
            'initial_balance' => 'required|numeric',
            'description' => 'nullable|string|max:500',
            'icon' => 'nullable|string|max:50',
            'color' => 'nullable|string|regex:/^#[0-9A-Fa-f]{6}$/',
            'include_in_total' => 'boolean',
            'credit_limit' => 'nullable|numeric|min:0',
            'interest_rate' => 'nullable|numeric|min:0|max:100',
            'account_number' => 'nullable|string|max:50',
            'bank_name' => 'nullable|string|max:100',
        ];
    }

    /**
     * Get custom messages for validator errors.
     */
    public function messages(): array
    {
        return [
            'name.required' => 'Account name is required.',
            'type.required' => 'Please select an account type.',
            'currency_id.required' => 'Please select a currency.',
            'initial_balance.required' => 'Initial balance is required.',
            'color.regex' => 'Color must be a valid hex color (e.g., #FF5733).',
        ];
    }
}
