<?php

namespace App\Http\Requests\V1\Purchase;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'purchase_date' => ['required', 'date'],
            'client_id' => ['required', 'integer', 'exists:clients,id'],
            'supply_amount' => ['required', 'numeric', 'min:0'],
            'tax_amount' => ['required', 'numeric', 'min:0'],
            'total_amount' => ['required', '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'],
        ];
    }

    public function messages(): array
    {
        return [
            'purchase_date.required' => __('validation.required', ['attribute' => '매입일자']),
            'client_id.required' => __('validation.required', ['attribute' => '거래처']),
            'client_id.exists' => __('validation.exists', ['attribute' => '거래처']),
            'supply_amount.required' => __('validation.required', ['attribute' => '공급가액']),
            'supply_amount.numeric' => __('validation.numeric', ['attribute' => '공급가액']),
            'tax_amount.required' => __('validation.required', ['attribute' => '세액']),
            'total_amount.required' => __('validation.required', ['attribute' => '합계']),
        ];
    }
}
