<?php

declare(strict_types=1);

namespace App\Http\Requests\ProjectRequest;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'title' => ['required', 'string', 'min:2', 'max:255'],
            'payload' => ['nullable', 'array'],
            'payload.product_name' => ['nullable', 'string', 'max:255'],
            'payload.category_id' => ['nullable', 'integer', 'exists:categories,id'],
            'payload.breed_id' => ['nullable', 'integer', 'exists:breeds,id'],
            'payload.product_id' => ['nullable', 'integer', 'exists:products,id'],
            'payload.quantity' => ['nullable', 'integer', 'min:1'],
            'payload.unit' => ['nullable', 'string', 'max:50'],
            'payload.unit_price' => ['nullable', 'numeric', 'min:0'],
            'payload.desc' => ['nullable', 'string', 'max:20000'],
            'payload.estimated_profit' => ['nullable', 'numeric', 'min:0'],
            'payload.province_id' => ['nullable', 'integer', 'exists:provinces,id'],
            'payload.county_id' => ['nullable', 'integer', 'exists:counties,id'],
            'payload.start_date' => ['nullable', 'date'],
            'payload.end_date' => ['nullable', 'date'],
            'payload.guarantor' => ['nullable', 'array'],
            'payload.guarantor.name' => ['nullable', 'string', 'max:255'],
            'payload.guarantor.national_code' => ['nullable', 'string', 'max:20'],
            'payload.guarantor.cellphone' => ['nullable', 'string', 'max:20'],
            'payload.guarantor.address' => ['nullable', 'string', 'max:2000'],
            'payload.unit_documents' => ['nullable', 'array'],
            'payload.unit_documents.*' => ['nullable'],
            'payload.facilities' => ['nullable', 'array'],
            'payload.facilities.*' => ['nullable'],
            'payload.facilities.*.name' => ['nullable', 'string', 'max:255'],
            'payload.facilities.*.count' => ['nullable', 'integer', 'min:0'],
            'payload.facilities.*.image' => ['nullable', 'string', 'max:2048'],
            'payload.facilities.*.description' => ['nullable', 'string', 'max:2000'],
        ];
    }

    public function messages(): array
    {
        return [
            'title.required' => 'عنوان پروژه الزامی است.',
        ];
    }
}
