<?php

namespace App\Services\Enterprise;

/**
 * ==============================================================
 * Enterprise Registry
 * --------------------------------------------------------------
 * Pack 2504-A1
 *
 * Single source of truth for all Enterprise Centers.
 *
 * DO NOT:
 *   - Query the database
 *   - Modify RBAC
 *   - Modify translations
 *   - Modify sidebar
 *
 * Future packs consume this registry.
 * ==============================================================
 */

final class EnterpriseRegistry
{
    /**
     * ----------------------------------------------------------
     * Registered Enterprise Modules
     * ----------------------------------------------------------
     */
    public static function modules(): array
    {
        return [

            'governance' => [

                'key' => 'governance',

                'label' =>
                    'Enterprise Governance Center',

                'label_key' =>
                    'menu.enterprise_governance_center',

                'label_ar' =>
                    'مركز الحوكمة المؤسسية',

                'icon' =>
                    'fa-solid fa-shield-halved',

                'route' =>
                    '/easychair/admin/governance',

                'module' =>
                    'governance',

                'roles' => [
                    'super_admin',
                    'org_admin',
                    'conference_chair'
                ],

                'enabled' => true

            ],

            'institutional_sustainability' => [

                'key' =>
                    'institutional_sustainability',

                'label' =>
                    'Enterprise Institutional Sustainability & Growth Intelligence Center',

                'label_key' =>
                    'menu.enterprise_institutional_sustainability_growth_intelligence_center',

                'label_ar' =>
                    'مركز الاستدامة المؤسسية والذكاء التنموي',

                'icon' =>
                    'fa-solid fa-seedling',

                'route' =>
                    '/easychair/admin/conference-home/enterprise-institutional-sustainability-growth-intelligence-center',

                'module' =>
                    'institutional_sustainability',

                'roles' => [
                    'super_admin',
                    'org_admin'
                ],

                'enabled' => true

            ],

            /*
            --------------------------------------------------
            Reserved Future Enterprise Centers
            --------------------------------------------------
            */

            'operations' => [

                'enabled' => false

            ],

            'analytics' => [

                'enabled' => false

            ],

            'ai' => [

                'enabled' => false

            ],

            'digital_twin' => [

                'enabled' => false

            ]

        ];
    }

    /**
     * ----------------------------------------------------------
     * Enabled Modules Only
     * ----------------------------------------------------------
     */
    public static function enabled(): array
    {
        return array_filter(

            self::modules(),

            static function ($module) {

                return !empty($module['enabled']);

            }

        );
    }

    /**
     * ----------------------------------------------------------
     * Get Single Module
     * ----------------------------------------------------------
     */
    public static function module(
        string $key
    ): ?array {

        $modules =
            self::modules();

        return $modules[$key] ?? null;
    }

    /**
     * ----------------------------------------------------------
     * Sidebar Items
     * ----------------------------------------------------------
     */
    public static function sidebar(): array
    {
        return self::enabled();
    }

    /**
     * ----------------------------------------------------------
     * Translation Keys
     * ----------------------------------------------------------
     */
    public static function translationKeys(): array
    {
        $keys = [];

        foreach (self::enabled() as $module) {

            if (!empty($module['label_key'])) {

                $keys[] =
                    $module['label_key'];

            }

        }

        return $keys;
    }

    /**
     * ----------------------------------------------------------
     * Module Count
     * ----------------------------------------------------------
     */
    public static function count(): int
    {
        return count(
            self::enabled()
        );
    }
}
