<?php

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

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

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

    public function rules(): array
    {
        return [
            'nama' => ['required', 'string', 'max:255'],
            'nik' => ['required', 'digits:16'],
            'tps_id' => [
                'required',
                'uuid',
                Rule::exists('tps', 'id')->where('desa_id', $this->user()->desa_id),
            ],
            'rt' => ['nullable', 'string', 'max:10'],
            'rw' => ['nullable', 'string', 'max:10'],
            'status_terdaftar' => ['sometimes', Rule::in(['terdaftar', 'tidak_terdaftar', 'pindah'])],
        ];
    }
}
