<?php

namespace App\Http\Requests\Admin;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'title' => 'required|string|max:255',
            'message' => 'required|string',
            'attachments' => 'nullable|array',
            'attachments.*' => 'file|max:10240',
            'publish_at' => 'nullable|date',
            'publish_type' => 'nullable|string|in:now,later',
            'target_type' => 'required|in:all,department,role,user',
            'department_ids' => 'required_if:target_type,department|array',
            'department_ids.*' => 'exists:departments,id',
            'role_ids' => 'required_if:target_type,role|array',
            'role_ids.*' => 'exists:roles,id',
            'user_ids' => 'required_if:target_type,user|array',
            'user_ids.*' => 'exists:users,id',
        ];
    }
}
