<?php

declare(strict_types=1);

namespace App\Http\Requests\Groups;

use Illuminate\Foundation\Http\FormRequest;

class StoreGroupProjectRequest 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'],
            'cover_path' => ['nullable', 'string', 'max:2048'],
            'cover_file' => ['nullable', 'image', 'mimes:jpg,jpeg,png,webp', 'max:5120'],
            'status' => ['nullable', 'in:' . implode(',', (array) config('groups.projects.statuses', []))],
            'visibility' => ['nullable', 'in:' . implode(',', (array) config('groups.projects.visibility_options', []))],
            'start_date' => ['nullable', 'date'],
            'target_date' => ['nullable', 'date', 'after_or_equal:start_date'],
            'lead_user_id' => ['nullable', 'integer'],
            'linked_collection_id' => ['nullable', 'integer'],
            'linked_featured_artwork_id' => ['nullable', 'integer'],
            'pinned_post_id' => ['nullable', 'integer'],
            'member_user_ids' => ['nullable', 'array'],
            'member_user_ids.*' => ['integer'],
        ];
    }
}