<?php

namespace App\Domains\Integration\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UpdateIntegrationRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        $integration = $this->route('integration');

        return [
            'name' => ['sometimes', 'required', 'string', 'max:255'],
            'url' => ['nullable', 'url', 'max:255'],
            'integration_data_schema' => ['nullable', 'array'],
            'requires_client_configuration' => ['sometimes', 'boolean'],
            // the code shouldn't ideally be updatable, but if it is:
            'integration_code' => ['sometimes', 'required', 'string', 'unique:integrations,integration_code,'.($integration->id ?? '')],
        ];
    }
}
