<?php

namespace App\Http\Requests\ESign;

use App\Models\ESign\EsignSignField;
use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'fields' => 'required|array|min:1',
            'fields.*.signer_id' => 'required|integer|exists:esign_signers,id',
            'fields.*.page_number' => 'required|integer|min:1',
            'fields.*.position_x' => 'required|numeric|min:0|max:100',
            'fields.*.position_y' => 'required|numeric|min:0|max:100',
            'fields.*.width' => 'required|numeric|min:1|max:100',
            'fields.*.height' => 'required|numeric|min:1|max:100',
            'fields.*.field_type' => 'nullable|string|in:' . implode(',', EsignSignField::FIELD_TYPES),
            'fields.*.field_label' => 'nullable|string|max:100',
            'fields.*.is_required' => 'nullable|boolean',
            'fields.*.sort_order' => 'nullable|integer|min:0',
        ];
    }

    public function messages(): array
    {
        return [
            'fields.required' => __('validation.required', ['attribute' => '서명 필드']),
            'fields.min' => '최소 1개 이상의 서명 필드가 필요합니다.',
        ];
    }
}
