<?php

namespace App\Http\Requests\Finance;

use Illuminate\Foundation\Http\FormRequest;

class StoreFinanceCostEntryRequest 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'],
            'category' => ['required', 'string', 'in:FEED,INPUTS,ENERGY,LABOR,FINGERLINGS,MAINTENANCE,OTHER'],
            'subcategory' => ['required', 'string', 'max:255'],
            'amount_crc' => ['required', 'numeric', 'min:0'],
            'quantity' => ['nullable', 'numeric', 'min:0'],
            'unit' => ['nullable', 'string', 'in:kg,g,ml,l,unit,kWh,hours'],
            'unit_cost_crc' => ['nullable', 'numeric', 'min:0'],
            'source' => ['required', 'string', 'in:AUTO,MANUAL'],
            'ref' => ['nullable', 'array'],
            'ref.inventory_movement_id' => ['nullable', 'integer'],
            'ref.daily_log_id' => ['nullable', 'integer'],
            'ref.task_id' => ['nullable', 'integer'],
            'ref.batch_split_event_id' => ['nullable', 'string', 'max:120'],
            'scope' => ['nullable', 'array'],
            'scope.tank_id' => ['nullable', 'integer'],
            'scope.batch_id' => ['nullable', 'integer'],
            'notes' => ['nullable', 'string', 'max:4000'],
            'created_at' => ['nullable', 'date'],
        ];
    }
}
