<?php

namespace App\Http\Requests;

use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;

class UpdateKaryawanRequest 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
    {
        $karyawanId = $this->karyawan?->id
            ?? Auth::user()?->karyawan?->id;

        return [
            'nrp' => 'required|string|unique:karyawans,nrp,' . $karyawanId,
            'nama' => 'required|string|max:255',
            'no_hp' => 'nullable|string|max:20',
            'atasan_id' => 'nullable',
            'jabatan_id' => 'required|exists:jabatans,id',
            'departemen_id' => 'required|exists:departemens,id',
            'foto' => 'nullable|image|mimes:jpeg,png,jpg|max:2048',
        ];
    }
}
