<?php

namespace App\Http\Requests\Finance;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'date' => ['sometimes', 'required', 'date_format:Y-m-d'],
            'memo' => ['sometimes', 'required', 'string', 'max:1000'],
            'status' => ['sometimes', 'required', 'string', 'in:DRAFT,POSTED'],
            'lines' => ['sometimes', 'required', 'array', 'min:1'],
            'lines.*.id' => ['required_with:lines', 'string', 'max:120'],
            'lines.*.account_id' => ['required_with:lines', 'string', 'max:120'],
            'lines.*.description' => ['nullable', 'string', 'max:1000'],
            'lines.*.debit_crc' => ['required_with:lines', 'numeric', 'min:0'],
            'lines.*.credit_crc' => ['required_with:lines', 'numeric', 'min:0'],
            'ref' => ['sometimes', 'nullable', 'array'],
            'ref.cost_entry_id' => ['nullable', 'string', 'max:120'],
            'ref.sale_entry_id' => ['nullable', 'string', 'max:120'],
            'updated_at' => ['sometimes', 'nullable', 'date'],
        ];
    }
}
