<?php

namespace App\Modules\HR\Attendance\Requests;

use App\Modules\HR\Attendance\Repositories\AttendanceCorrectionRequestRepository;
use Illuminate\Foundation\Http\FormRequest;

class ReviewAttendanceCorrectionRequest extends FormRequest
{
    public function authorize(): bool
    {
        $user = $this->user();
        if ($user === null || $user->tenant_id === null) {
            return false;
        }
        $id = (int) $this->route('correction');
        if ($id < 1) {
            return false;
        }
        $row = app(AttendanceCorrectionRequestRepository::class)->findForTenant((int) $user->tenant_id, $id);

        return $row !== null && $user->can('review', $row);
    }

    /**
     * @return array<string, array<int, string>>
     */
    public function rules(): array
    {
        return [
            'reviewer_note' => ['required', 'string', 'max:5000'],
        ];
    }
}
