<?php

namespace App\Http\Requests\Admin\Manage;

use App\Enums\UserRole;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class AnnouncementRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()->can($this->isMethod('post') ? 'create-announcements' : 'update-announcements');
    }

    public function rules(): array
    {
        return [
            'title' => ['required', 'string', 'max:200'],
            'content' => ['required', 'string'],
            'target_roles' => ['required', 'array', 'min:1'],
            'target_roles.*' => [
                Rule::enum(UserRole::class)->only([UserRole::Mahasiswa, UserRole::Dosen]),
            ],
        ];
    }
}
