<?php

namespace Modules\Lpj\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class PenilaianRequest extends FormRequest
{
    /**
     * Get the validation rules that apply to the request.
     */



    public function rules(): array
    {


        $action = $this->input('action');

        if ($action === 'revisi') {
            return [
                'dokumen' => 'required|file|mimes:pdf',
                'keterangan' => 'required|string',
            ];
        }

        return [
            'jenis_penilaian_id' => 'required|max:255',
            'teams_id'           => 'required|max:255',
            'tanggal_kunjungan'  => 'required|max:255',
            'status'             => 'required|string',
            'nomor_registrasi'   => 'required|string',
            'surveyor_id'        => 'nullable|required_without_all:penilai_surveyor_id,surveyor_region_id,penilai_region_id,penilai_id',
            'penilai_id'         => 'nullable|required_without_all:penilai_surveyor_id,surveyor_region_id,penilai_region_id,surveyor_id',
            'penilai_surveyor_id' => 'nullable',
            'surveyor_region_id' => 'nullable|required_without_all:penilai_surveyor_id,penilai_region_id,penilai_id,surveyor_id',
            'penilai_region_id'  => 'nullable|required_without_all:penilai_surveyor_id,surveyor_region_id,penilai_id,surveyor_id',
            'surveyor_penilai_region_id' => 'nullable',
            'keterangan'         => 'nullable',
        ];

    }


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

    protected function prepareForValidation()
    {
        // Menetapkan nilai default untuk 'status' jika tidak ada dalam request
        $this->merge([
            'status' => $this->status ?? 'assign',
        ]);
    }
}
