from datetime import datetime

from .iam_constant import (
    PRINCIPAL_TYPE_USER,
    PRINCIPAL_TYPE_ADMIN,
    PRINCIPAL_TYPE_SUBADMIN,
    PRINCIPAL_SOURCE_APP,
    PRINCIPAL_SOURCE_WEB,
    PRINCIPAL_SOURCE_GOOGLE,
    PRINCIPAL_SOURCE_APPLE,
    ACTION_CREATE,
    ACTION_READ,
    ACTION_UPDATE,
    ACTION_DELETE,
    RESOURCE_MANAGE_DASHBOARD,
    RESOURCE_MANAGE_IAM,
    RESOURCE_MANAGE_USER,
    RESOURCE_MANAGE_CONTACT_US,
    RESOURCE_MANAGE_FEEDBACK,
    RESOURCE_MANAGE_FAQS,
    RESOURCE_MANAGE_T_C,
    RESOURCE_MANAGE_CMS,
    RESOURCE_MANAGE_PRIVACYPOLICY,
    RESOURCE_MANAGE_SUPPORT,
    RESOURCE_MANAGE_NOTIFICATION
)

class IAMPrincipalType:
    ADMIN = PRINCIPAL_TYPE_ADMIN
    SUBADMIN = PRINCIPAL_TYPE_SUBADMIN
    USER = PRINCIPAL_TYPE_USER

    categories = [
        ADMIN,
        SUBADMIN,
        USER,
    ]

    @staticmethod
    def create_iam_principal_type_fixture_data():
        iam_category_fixture_data = []
        created_on = datetime.now().isoformat()
        modified_on = datetime.now().isoformat()
        for idx, category in enumerate(IAMPrincipalType.categories, start=1):
            iam_category_fixture_data.append(
                {
                    "model": "module_iam.iamprincipaltype",
                    "pk": idx,
                    "fields": {
                        "name": category,
                        "label": category,
                        "slug": category,
                        "created_on": created_on,
                        "modified_on": modified_on,
                    },
                }
            )
        return iam_category_fixture_data

class IAMPrincipalSource:
    source = [
        PRINCIPAL_SOURCE_APP,
        PRINCIPAL_SOURCE_WEB,
        PRINCIPAL_SOURCE_GOOGLE,
        PRINCIPAL_SOURCE_APPLE
    ]

    @staticmethod
    def create_iam_principal_source_fixture_data():
        iam_principal_source_fixture_data = []
        created_on = datetime.now().isoformat()
        modified_on = datetime.now().isoformat()

        for idx, principal_source in enumerate(IAMPrincipalSource.source, start=1,):
            iam_principal_source_fixture_data.append(
                {
                    "model": "module_iam.iamprincipalsource",
                    "pk": idx,
                    "fields": {
                        "name": principal_source,
                        "label": principal_source,
                        "slug": principal_source,
                        "created_on": created_on,
                        "modified_on": modified_on,
                    },
                }
            )

        return iam_principal_source_fixture_data

class IAMActions:
    CREATE = ACTION_CREATE
    READ = ACTION_READ
    UPDATE = ACTION_UPDATE
    DELETE = ACTION_DELETE

    actions = [
        CREATE,
        READ,
        UPDATE,
        DELETE,
    ]

    @staticmethod
    def create_iam_action_fixture_data():
        iam_action_fixture_data = []
        created_on = datetime.now().isoformat()
        modified_on = datetime.now().isoformat()
        for idx, action in enumerate(IAMActions.actions, start=1):
            iam_action_fixture_data.append(
                {
                    "model": "module_iam.iamappaction",
                    "pk": idx,
                    "fields": {
                        "name": action,
                        "label": action,
                        "slug": action,
                        "created_on": created_on,
                        "modified_on": modified_on,
                    },
                }
            )
        return iam_action_fixture_data

class IAMResources:
    IAM = RESOURCE_MANAGE_IAM
    USER = RESOURCE_MANAGE_USER
    SUPPORT = RESOURCE_MANAGE_SUPPORT
    CONTACT_US = RESOURCE_MANAGE_CONTACT_US
    FEEDBACK = RESOURCE_MANAGE_FEEDBACK
    CMS = RESOURCE_MANAGE_CMS
    FAQS = RESOURCE_MANAGE_FAQS
    T_C = RESOURCE_MANAGE_T_C
    PRIVACYPOLICY = RESOURCE_MANAGE_PRIVACYPOLICY
    NOTIFICATION = RESOURCE_MANAGE_NOTIFICATION

    resources = [
        IAM,
        USER,
        SUPPORT,
        CONTACT_US,
        FEEDBACK,
        CMS,
        FAQS,
        T_C,
        PRIVACYPOLICY,
        NOTIFICATION,
    ]

    @staticmethod
    def create_iam_resource_fixture_data():
        iam_resource_fixture_data = []
        created_on = datetime.now().isoformat()
        modified_on = datetime.now().isoformat()
        for idx, resource in enumerate(IAMResources.resources, start=1):
            iam_resource_fixture_data.append(
                {
                    "model": "module_iam.iamappresource",
                    "pk": idx,
                    "fields": {
                        "name": resource,
                        "label": resource,
                        "slug": resource,
                        "created_on": created_on,
                        "modified_on": modified_on,
                        "action": [1, 2, 3, 4],
                    },
                }
            )
        return iam_resource_fixture_data
