# app/modules/core/definition.py
"""
Core Platform module definition.

Dashboard, settings, and profile management.
Required for basic operation - cannot be disabled.
"""

from app.modules.base import (
    MenuItemDefinition,
    MenuSectionDefinition,
    ModuleDefinition,
    PermissionDefinition,
)
from app.modules.enums import FrontendType

core_module = ModuleDefinition(
    code="core",
    name="Core Platform",
    description="Dashboard, settings, and profile management. Required for basic operation.",
    version="1.0.0",
    is_core=True,
    is_self_contained=True,
    # Module-driven permissions
    permissions=[
        PermissionDefinition(
            id="dashboard.view",
            label_key="core.permissions.dashboard_view",
            description_key="core.permissions.dashboard_view_desc",
            category="dashboard",
        ),
        PermissionDefinition(
            id="settings.view",
            label_key="core.permissions.settings_view",
            description_key="core.permissions.settings_view_desc",
            category="settings",
        ),
        PermissionDefinition(
            id="settings.edit",
            label_key="core.permissions.settings_edit",
            description_key="core.permissions.settings_edit_desc",
            category="settings",
        ),
        PermissionDefinition(
            id="settings.theme",
            label_key="core.permissions.settings_theme",
            description_key="core.permissions.settings_theme_desc",
            category="settings",
        ),
        PermissionDefinition(
            id="settings.domains",
            label_key="core.permissions.settings_domains",
            description_key="core.permissions.settings_domains_desc",
            category="settings",
            is_owner_only=True,  # Only owners can manage domains
        ),
    ],
    features=[
        "dashboard",
        "settings",
        "profile",
    ],
    # Legacy menu_items (IDs only)
    menu_items={
        FrontendType.ADMIN: [
            "dashboard",
            "my_account",
            "settings",
            "email-templates",
        ],
        FrontendType.STORE: [
            "dashboard",
            "my_account",
            "profile",
            "settings",
            "email-templates",
        ],
        FrontendType.MERCHANT: [
            "dashboard",
        ],
    },
    # New module-driven menu definitions
    menus={
        FrontendType.ADMIN: [
            MenuSectionDefinition(
                id="main",
                label_key=None,  # No header for main section
                icon=None,
                order=0,
                is_collapsible=False,
                items=[
                    MenuItemDefinition(
                        id="dashboard",
                        label_key="core.menu.dashboard",
                        icon="home",
                        route="/admin/dashboard",
                        order=10,
                        is_mandatory=True,
                    ),
                ],
            ),
            MenuSectionDefinition(
                id="account",
                label_key="core.menu.account",
                icon="user",
                order=890,
                items=[
                    MenuItemDefinition(
                        id="my_account",
                        label_key="core.menu.my_account",
                        icon="user-circle",
                        route="/admin/my-account",
                        order=5,
                        is_mandatory=True,
                    ),
                ],
            ),
            MenuSectionDefinition(
                id="settings",
                label_key="core.menu.platform_settings",
                icon="cog",
                order=900,
                items=[
                    MenuItemDefinition(
                        id="settings",
                        label_key="core.menu.general",
                        icon="cog",
                        route="/admin/settings",
                        order=10,
                        is_mandatory=True,
                    ),
                ],
            ),
        ],
        FrontendType.MERCHANT: [
            MenuSectionDefinition(
                id="main",
                label_key=None,
                icon=None,
                order=0,
                is_collapsible=False,
                items=[
                    MenuItemDefinition(
                        id="dashboard",
                        label_key="core.menu.dashboard",
                        icon="home",
                        route="/merchants/dashboard",
                        order=10,
                        is_mandatory=True,
                    ),
                ],
            ),
        ],
        FrontendType.STORE: [
            MenuSectionDefinition(
                id="main",
                label_key=None,
                icon=None,
                order=0,
                is_collapsible=False,
                items=[
                    MenuItemDefinition(
                        id="dashboard",
                        label_key="core.menu.dashboard",
                        icon="home",
                        route="/store/{store_code}/dashboard",
                        order=10,
                        is_mandatory=True,
                        requires_permission="dashboard.view",
                    ),
                ],
            ),
            MenuSectionDefinition(
                id="account",
                label_key="core.menu.account_settings",
                icon="user",
                order=900,
                items=[
                    MenuItemDefinition(
                        id="my_account",
                        label_key="core.menu.my_account",
                        icon="user-circle",
                        route="/store/{store_code}/my-account",
                        order=5,
                    ),
                    MenuItemDefinition(
                        id="profile",
                        label_key="core.menu.store_settings",
                        icon="user",
                        route="/store/{store_code}/profile",
                        order=10,
                    ),
                    MenuItemDefinition(
                        id="settings",
                        label_key="core.menu.settings",
                        icon="cog",
                        route="/store/{store_code}/settings",
                        order=20,
                        is_mandatory=True,
                        requires_permission="settings.view",
                    ),
                ],
            ),
        ],
    },
)

__all__ = ["core_module"]
