<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;

class ProfileRequest extends FormRequest
{
    /** Selalu izinkan (atau sesuaikan logic Anda) */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Inject role_id = 2 ke dalam request sebelum validasi.
     */
    protected function prepareForValidation(): void
    {
        $this->merge([
            'role_id' => 2,   // 2 = role "user"
        ]);
    }

    /** Aturan validasi */
    public function rules(): array
    {
        return [
            'name'     => 'required|string|max:100',
            'email'    => 'required|email|unique:users,email,' . Auth::id(),
            'no_telp'  => 'required|string|max:20',
            'password' => 'nullable|string|min:6',
            'role_id'  => 'in:2',   // pastikan nilai akhirnya memang 2
        ];
    }
}
