<?php

namespace App\Http\Requests\Finance;

use Illuminate\Foundation\Http\FormRequest;

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

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