<?php

namespace App\Http\Requests\V1\Purchase;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'purchase_date' => ['sometimes', 'date'],
            'client_id' => ['sometimes', 'integer', 'exists:clients,id'],
            'supply_amount' => ['sometimes', 'numeric', 'min:0'],
            'tax_amount' => ['sometimes', 'numeric', 'min:0'],
            'total_amount' => ['sometimes', 'numeric', 'min:0'],
            'purchase_type' => ['nullable', 'string', 'max:50'],
            'description' => ['nullable', 'string', 'max:1000'],
            'withdrawal_id' => ['nullable', 'integer', 'exists:withdrawals,id'],
            'approval_id' => ['nullable', 'integer', 'exists:approvals,id'],
            'tax_invoice_received' => ['sometimes', 'boolean'],
        ];
    }

    public function messages(): array
    {
        return [
            'client_id.exists' => __('validation.exists', ['attribute' => '거래처']),
            'supply_amount.numeric' => __('validation.numeric', ['attribute' => '공급가액']),
            'withdrawal_id.exists' => __('validation.exists', ['attribute' => '출금']),
        ];
    }
}
