<?php

namespace App\Http\Requests\V1\GeneralJournalEntry;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'journal_memo' => ['sometimes', 'nullable', 'string', 'max:1000'],
            'rows' => ['sometimes', 'array', 'min:1'],
            'rows.*.side' => ['required_with:rows', 'in:debit,credit'],
            'rows.*.account_subject_id' => ['required_with:rows', 'string', 'max:10'],
            'rows.*.vendor_id' => ['nullable', 'integer'],
            'rows.*.debit_amount' => ['required_with:rows', 'integer', 'min:0'],
            'rows.*.credit_amount' => ['required_with:rows', 'integer', 'min:0'],
            'rows.*.memo' => ['nullable', 'string', 'max:300'],
        ];
    }

    public function messages(): array
    {
        return [
            'rows.*.side.required_with' => '차/대 구분을 선택하세요.',
            'rows.*.side.in' => '차/대 구분이 올바르지 않습니다.',
            'rows.*.account_subject_id.required_with' => '계정과목을 선택하세요.',
            'rows.*.debit_amount.required_with' => '차변 금액을 입력하세요.',
            'rows.*.credit_amount.required_with' => '대변 금액을 입력하세요.',
        ];
    }
}
