<?php

namespace App\Http\Requests\Admin\AcademicClasses;

use Illuminate\Foundation\Http\FormRequest;

class GradeSubmissionRequest extends FormRequest
{
    public function authorize(): bool
    {
        if (! $this->user()->can('update-assignment-submissions')) {
            return false;
        }

        $user = $this->user();
        $assignment = $this->route('assignment');

        if ($user->hasRole('dosen') && $assignment?->courseClass?->lecturer_id !== $user->lecturer?->id) {
            return false;
        }

        return true;
    }

    public function rules(): array
    {
        return [
            'score' => ['nullable', 'numeric', 'min:0', 'max:100'],
        ];
    }
}
