<?php

namespace App\Modules\Pilkades\Http\Requests\AdminDesa;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class StoreCandidateRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()->isAdminDesa();
    }

    public function rules(): array
    {
        $candidateId = $this->route('candidate')?->id;

        return [
            'nomor_urut' => [
                'required',
                'integer',
                'min:1',
                Rule::unique('candidates', 'nomor_urut')
                    ->where('desa_id', $this->user()->desa_id)
                    ->ignore($candidateId),
            ],
            'nama_lengkap' => ['required', 'string', 'max:255'],
            'foto' => ['nullable', 'image', 'max:2048'],
            'status' => ['sometimes', Rule::in(['aktif', 'nonaktif'])],
            'tempat_lahir' => ['nullable', 'string', 'max:255'],
            'tanggal_lahir' => ['nullable', 'date'],
            'pendidikan_terakhir' => ['nullable', 'string', 'max:255'],
            'alamat' => ['nullable', 'string', 'max:255'],
            'riwayat_pekerjaan' => ['nullable', 'string'],
            'visi' => ['nullable', 'string'],
            'misi' => ['nullable', 'string'],
        ];
    }
}
