<?php

declare(strict_types=1);

namespace App\Http\Requests\Groups;

use Illuminate\Foundation\Http\FormRequest;

class StoreGroupEventRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user() !== null;
    }

    public function rules(): array
    {
        return [
            'title' => ['required', 'string', 'min:2', 'max:180'],
            'summary' => ['nullable', 'string', 'max:320'],
            'description' => ['nullable', 'string', 'max:40000'],
            'event_type' => ['nullable', 'in:' . implode(',', (array) config('groups.events.types', []))],
            'visibility' => ['nullable', 'in:' . implode(',', (array) config('groups.events.visibility_options', []))],
            'status' => ['nullable', 'in:' . implode(',', (array) config('groups.events.statuses', []))],
            'start_at' => ['nullable', 'date'],
            'end_at' => ['nullable', 'date', 'after_or_equal:start_at'],
            'timezone' => ['nullable', 'string', 'max:80'],
            'cover_path' => ['nullable', 'string', 'max:2048'],
            'cover_file' => ['nullable', 'image', 'mimes:jpg,jpeg,png,webp', 'max:5120'],
            'location' => ['nullable', 'string', 'max:180'],
            'external_url' => ['nullable', 'url', 'max:2048'],
            'linked_project_id' => ['nullable', 'integer'],
            'linked_collection_id' => ['nullable', 'integer'],
            'linked_challenge_id' => ['nullable', 'integer'],
            'is_featured' => ['nullable', 'boolean'],
        ];
    }
}