<?php

namespace App\Http\Requests\Design\Model;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'code' => 'required|string|max:100',
            'name' => 'required|string|max:200',
            'category_id' => 'nullable|integer',
            'lifecycle' => 'nullable|string|max:50',
            'description' => 'nullable|string',
            'is_active' => 'boolean',
        ];
    }

    public function messages(): array
    {
        return [
            'code.required' => __('validation.required', ['attribute' => '모델코드']),
            'name.required' => __('validation.required', ['attribute' => '모델명']),
        ];
    }

    protected function prepareForValidation(): void
    {
        if ($this->has('code')) {
            $this->merge(['code' => trim($this->input('code'))]);
        }
    }
}
