<?php

namespace App\Http\Requests\V1\Sale;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'sale_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'],
            'description' => ['nullable', 'string', 'max:1000'],
            'deposit_id' => ['nullable', 'integer', 'exists:deposits,id'],
        ];
    }

    public function messages(): array
    {
        return [
            'sale_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' => '합계']),
        ];
    }
}
