<?php

namespace App\Http\Requests\Approval;

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

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

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

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

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