<?php

namespace PloverCRM\Core\Services;

/**
 * Registry describing which internal capabilities own which system fields
 * and when those capabilities should provision fields.
 */
class SystemCapabilityRegistry
{
    public static function all(): array
    {
        return [
            SystemFieldRegistry::CAPABILITY_CORE_STAGES => [
                'label' => 'Core stages',
                'module_id' => null,
                'fields' => [SystemFieldRegistry::FIELD_STAGE],
                'provisioning' => 'core',
            ],
            SystemFieldRegistry::CAPABILITY_TRACKING_ENRICHMENT => [
                'label' => 'Contact enrichment tracking',
                'module_id' => 'contact_enrichment',
                'fields' => array_map(
                    static fn (array $field): string => (string) $field['slug'],
                    SystemFieldRegistry::getFieldsForCapability(SystemFieldRegistry::CAPABILITY_TRACKING_ENRICHMENT)
                ),
                'provisioning' => 'lazy_runtime',
            ],
            SystemFieldRegistry::CAPABILITY_META_LEAD_ADS => [
                'label' => 'Meta Lead Ads metadata',
                'module_id' => 'integrations',
                'fields' => [SystemFieldRegistry::FIELD_FACEBOOK_LEAD_ID],
                'provisioning' => 'lazy_runtime',
            ],
        ];
    }

    public static function get(string $capabilityId): ?array
    {
        $all = self::all();
        return $all[$capabilityId] ?? null;
    }
}
