<?php

declare(strict_types=1);

namespace App\Http\Requests\Groups;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        $allowedRoles = config('groups.recruitment.roles', []);
        $allowedSkills = config('groups.recruitment.skills', []);
        $allowedContactModes = config('groups.recruitment.contact_modes', ['join_request', 'direct_message', 'external_link']);
        $allowedVisibility = config('groups.recruitment.visibility_options', ['public', 'members_only', 'private']);

        return [
            'is_recruiting' => ['required', 'boolean'],
            'headline' => ['nullable', 'string', 'max:180'],
            'description' => ['nullable', 'string', 'max:4000'],
            'roles_json' => ['nullable', 'array', 'max:12'],
            'roles_json.*' => ['string', 'max:80', 'in:' . implode(',', $allowedRoles)],
            'skills_json' => ['nullable', 'array', 'max:20'],
            'skills_json.*' => ['string', 'max:80', 'in:' . implode(',', $allowedSkills)],
            'contact_mode' => ['nullable', 'string', 'max:32', 'in:' . implode(',', $allowedContactModes)],
            'visibility' => ['nullable', 'in:' . implode(',', $allowedVisibility)],
        ];
    }
}