<?php

namespace App\Http\Requests\Employee;

use App\Models\Personality;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class PersonalityRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'personality_code' => ['required', 'string', 'max:255'],
            'personality' => ['required', 'string', 'max:255', Rule::unique(Personality::class)->ignore($this->personalities)],
            'careers' => ['required'],
            'desc' => ['required'],
            'image_url' => ['required', 'image', 'mimes:jpeg,png,jpg', 'max:2048']
        ];
    }

    public function messages(): array
    {
        return [
            'personality_code.required' => 'Kode kepribadian harus diisi.',
            'personality_code.string' => 'Kode kepribadian harus berupa teks.',
            'personality_code.max' => 'Kode kepribadian tidak boleh lebih dari 255 karakter.',
            'personality.required' => 'Tipe Kepribadian harus diisi.',
            'personality.string' => 'Tipe Kepribadian harus berupa teks.',
            'personality.max' => 'Tipe Kepribadian tidak boleh lebih dari 255 karakter.',
            'personality.unique' => 'Tipe Kepribadian telah digunakan.',
            'careers.required' => 'Karir harus dipilih.',
            'desc.required' => 'Deskripsi kepribadian harus diisi.',
            'image_url.required' => 'Gambar harus diisi.',
            'image_url.image' => 'File harus berupa gambar.',
            'image_url.mimes' => 'Gambar harus berformat jpeg, png, jpg.',
            'image_url.max' => 'Gambar tidak boleh lebih dari 2MB.'
        ];
    }
}
