<?php

declare(strict_types=1);

namespace App\Http\Requests\Project;

use App\Models\Project;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

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

    public function rules(): array
    {
        return [
            'is_draft' => ['nullable', 'boolean'],
            'name' => ['sometimes', 'required', 'string', 'min:2', 'max:255'],
            'excerpt' => ['nullable', 'string', 'max:1000'],
            'desc' => ['nullable', 'string', 'max:20000'],
            'category_id' => ['nullable', 'integer', 'exists:categories,id'],
            'breed_id' => ['nullable', 'integer', 'exists:breeds,id'],
            'product_id' => ['nullable', 'integer', 'exists:products,id'],
            'producer_id' => ['nullable', 'integer', 'exists:producers,id'],
            'user_id' => ['nullable', 'integer', 'exists:users,id'],
            'quantity' => ['nullable', 'integer', 'min:1'],
            'unit' => ['nullable', 'string', Rule::in(array_keys(Project::unitOptions()))],
            'unit_price' => ['nullable', 'numeric', 'min:0'],
            'images' => ['nullable', 'array'],
            'images.*' => ['string', 'max:500'],
            'presale_start' => ['nullable', 'date'],
            'presale_end' => ['nullable', 'date', 'after_or_equal:presale_start'],
            'start_date' => ['nullable', 'date'],
            'end_date' => ['nullable', 'date', 'after_or_equal:start_date'],
            'deadline' => ['nullable', 'date'],
            'province_id' => ['nullable', 'integer', 'exists:provinces,id'],
            'county_id' => ['nullable', 'integer', 'exists:counties,id'],
            'address' => ['nullable', 'string', 'max:1000'],
            'budget' => ['nullable', 'numeric', 'min:0'],
            'estimated_profit' => ['nullable', 'numeric', 'min:0'],
            'contract_text' => ['nullable', 'string', 'max:50000'],
            'sale_registration_enabled' => ['nullable', 'boolean'],
            'sale_deactivation_at' => ['nullable', 'date'],
            'status' => ['nullable', 'string', Rule::in(array_keys(Project::statusOptions()))],
            'notes' => ['nullable', 'string', 'max:5000'],
        ];
    }
}
