<?php

namespace App\Http\Requests\Mortality;

use Illuminate\Foundation\Http\FormRequest;

class MortalityRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'farm_id' => ["required", "integer", "exists:farms,id"],
            'farm_code' => ["required", "string"],
            'farm_name' => ["required", "string"],
            'week' => ["required", "integer"],
            'total_mortality' => ["required", "integer"],
            'synced_status' => ["required", "string"],

            'mortality_line' => ["required", "array", "min:1"],
            'mortality_line.*.batch_id' => ["required", "integer", "exists:batches,id"],
            'mortality_line.*.batch_no' => ["required", "string"],
            'mortality_line.*.building_id' => ["required", "integer", "exists:buildings,id"],
            'mortality_line.*.building_name' => ["required", "string"],
            'mortality_line.*.mortality_date' => ["required", "date_format:m/d/Y"],
            'mortality_line.*.age' => ["accepted", "integer", "min:1"],
            'mortality_line.*.quantity' => ["required", "integer", "min:0"],
        ];
    }
}
