<?php

namespace PloverCRM\Core\Api;

use PloverCRM\Core\Container;

/**
 * API Manager
 * 
 * Manages REST API endpoints
 */
class ApiManager
{
    /**
     * @var Container
     */
    private $container;

    /**
     * Constructor
     * 
     * @param Container $container
     */
    public function __construct(Container $container)
    {
        $this->container = $container;
    }

    /**
     * Initialize API
     */
    public function init(): void
    {
        add_action('rest_api_init', [$this, 'registerEndpoints']);
    }

    /**
     * Register all endpoints
     */
    public function registerEndpoints(): void
    {
        $endpointGroups = [
            'plover-crm/v1' => [
                new V1\AuthEndpoint($this->container),
                new V1\ContactsEndpoint($this->container),
                new V1\ListsEndpoint($this->container),
                new V1\TagsEndpoint($this->container),
                new V1\NotesEndpoint($this->container),
                new V1\CustomFieldsEndpoint($this->container),
                new V1\CustomFieldSettingsEndpoint($this->container),
                new V1\InfoEndpoint($this->container),
                new V1\StatsEndpoint($this->container),
                new V1\GrowthEndpoint($this->container),
                new V1\ActiveColumnsEndpoint($this->container),
                new V1\GeneralSettingsEndpoint($this->container),
                new V1\BusinessInformationSettingsEndpoint($this->container),
                new V1\BusinessInformationLogoEndpoint($this->container),
                new V1\SetupEndpoint($this->container),
                new V1\WorkspaceEndpoint($this->container),
                new V1\FeatureLogsEndpoint($this->container),
                new V1\BulkEndpoint($this->container),
                new V1\SearchEndpoint($this->container),
                new V1\PlaceholdersEndpoint($this->container),
                new V1\LicenseEndpoint($this->container),
                new V1\PushNotificationSettingsEndpoint($this->container),
                new V1\MobileNotificationsEndpoint($this->container),
                new V1\ActivityTypesEndpoint($this->container),
                new V1\StagesEndpoint($this->container),
                new V1\RolesEndpoint($this->container),
                new V1\UsersEndpoint($this->container),
                new V1\AccessPasswordEndpoint($this->container),
                new V1\AccessAvatarEndpoint($this->container),
                new V1\WebPushEndpoint($this->container),
            ],
            'plover-crm/v2' => [
                new V2\BootstrapEndpoint($this->container),
            ],
        ];

        foreach ($endpointGroups as $namespace => $endpoints) {
            foreach ($endpoints as $endpoint) {
                $endpoint->register($namespace);
            }
        }
    }
}
