<?php

namespace App\Modules\HR\Recruitment\Requests;

use App\Modules\HR\Recruitment\Models\RecruitmentInterviewScorecard;
use App\Modules\HR\Recruitment\Support\ScorecardRecommendation;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class StoreInterviewScorecardRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->can('create', RecruitmentInterviewScorecard::class) ?? false;
    }

    /** @return array<string, mixed> */
    public function rules(): array
    {
        return $this->baseRules();
    }

    /** @return array<string, mixed> */
    protected function baseRules(): array
    {
        $tenantId = $this->user()?->tenant_id;

        return [
            'interview_id' => [
                'required',
                'integer',
                Rule::exists('recruitment_interviews', 'id')->where(
                    fn ($q) => $q->where('tenant_id', $tenantId)->whereNull('deleted_at')
                ),
            ],
            'overall_score' => ['required', 'integer', 'min:1', 'max:100'],
            'recommendation' => ['required', 'string', Rule::in(ScorecardRecommendation::all())],
            'strengths' => ['nullable', 'string', 'max:5000'],
            'weaknesses' => ['nullable', 'string', 'max:5000'],
            'notes' => ['nullable', 'string', 'max:5000'],
        ];
    }
}
