<?php

namespace App\Http\Requests\Approval;

use App\Models\Tenants\ApprovalLine;
use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        $stepTypes = implode(',', ApprovalLine::STEP_TYPES);

        return [
            'name' => 'nullable|string|max:100',
            'steps' => 'nullable|array|min:1',
            'steps.*.type' => "required_with:steps|string|in:{$stepTypes}",
            'steps.*.user_id' => 'required_with:steps|integer|exists:users,id',
            'is_default' => 'nullable|boolean',
        ];
    }

    public function messages(): array
    {
        return [
            'steps.min' => __('validation.min.array', ['attribute' => '결재단계', 'min' => 1]),
            'steps.*.type.in' => __('validation.in', ['attribute' => '단계유형']),
            'steps.*.user_id.exists' => __('validation.exists', ['attribute' => '결재자']),
        ];
    }
}
