<?php

declare(strict_types=1);

namespace CpCreation\VitiCore\Commerce\Catalog\Enrollment;

final readonly class CatalogEnrollmentPayload
{
    public function __construct(
        public string $schemaVersion,
        public string $instanceId,
        public string $name,
        public string $merchantName,
        public string $baseUrl,
        public string $authAudience,
        #[\SensitiveParameter]
        public string $webhookSecret,
        public bool $catalogEnabled = true,
        public bool $monitoringEnabled = false,
    ) {}

    /**
     * @return array{
     *     schema_version: string,
     *     instance_id: string,
     *     name: string,
     *     merchant_name: string,
     *     base_url: string,
     *     auth_audience: string,
     *     webhook_secret: string,
     *     features: array{catalog: bool, monitoring: bool}
     * }
     */
    public function toArray(): array
    {
        return [
            'schema_version' => $this->schemaVersion,
            'instance_id' => $this->instanceId,
            'name' => $this->name,
            'merchant_name' => $this->merchantName,
            'base_url' => $this->baseUrl,
            'auth_audience' => $this->authAudience,
            'webhook_secret' => $this->webhookSecret,
            'features' => [
                'catalog' => $this->catalogEnabled,
                'monitoring' => $this->monitoringEnabled,
            ],
        ];
    }
}
