<?php

namespace App\Http\Requests;

use App\Models\Goal;
use Illuminate\Foundation\Http\FormRequest;

class StoreGoalRequest 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',
            'target_amount' => 'required|numeric|min:0.01',
            'current_amount' => 'nullable|numeric|min:0',
            'currency_id' => 'required|exists:currencies,id',
            'target_date' => 'nullable|date|after:today',
            'icon' => 'nullable|string|max:50',
            'color' => 'nullable|string|regex:/^#[0-9A-Fa-f]{6}$/',
            'description' => 'nullable|string|max:1000',
        ];
    }

    /**
     * Get custom messages for validator errors.
     */
    public function messages(): array
    {
        return [
            'name.required' => 'Nama target wajib diisi.',
            'target_amount.required' => 'Jumlah target wajib diisi.',
            'target_amount.min' => 'Jumlah target harus lebih dari nol.',
            'currency_id.required' => 'Pilih mata uang.',
            'target_date.after' => 'Tanggal target harus di masa depan.',
            'color.regex' => 'Warna harus berupa kode hex (contoh: #FF5733).',
        ];
    }
}
