from enum import unique, auto

from partner.permissions import PartnerPermission
from common.authentication_utilities import AutoNameEnum


@unique
class PartnerRole(AutoNameEnum):
    """
    Editing names here WILL break roles saved in DB
    """
    ADMIN = auto()
    EDITOR = auto()
    READER = auto()

    @classmethod
    def get_choices(cls):
        return [(role.name, ROLE_LABELS[role]) for role in cls]


ROLE_LABELS = {
    PartnerRole.ADMIN: 'Administrator',
    PartnerRole.EDITOR: 'Editor',
    PartnerRole.READER: 'Reader',
}


# HQ Roles have different permission scopes than ordinary roles
PARTNER_ROLE_PERMISSIONS = {
    True: {  # INGO HQ
        PartnerRole.ADMIN: frozenset([
            PartnerPermission.REGISTER,
            PartnerPermission.CREATE_COUNTRY_OFFICE,
            PartnerPermission.CFEI_VIEW,
            PartnerPermission.VIEW_DASHBOARD,
            PartnerPermission.MANAGE_USERS,
            PartnerPermission.CFEI_PINNING,
            PartnerPermission.CFEI_ANSWER_SELECTION,
            PartnerPermission.UCN_VIEW,
            PartnerPermission.UCN_DRAFT,
            PartnerPermission.RECEIVE_NOTIFICATIONS,
            PartnerPermission.UCN_EDIT,
            PartnerPermission.UCN_SUBMIT,
            PartnerPermission.UCN_DELETE,
            PartnerPermission.EDIT_PROFILE,
            PartnerPermission.EDIT_HQ_PROFILE,
            PartnerPermission.DSR_VIEW,
            PartnerPermission.DSR_ANSWER,
        ]),
        PartnerRole.EDITOR: frozenset([
            PartnerPermission.CREATE_COUNTRY_OFFICE,
            PartnerPermission.CFEI_VIEW,
            PartnerPermission.VIEW_DASHBOARD,
            PartnerPermission.CFEI_PINNING,
            PartnerPermission.CFEI_ANSWER_SELECTION,
            PartnerPermission.UCN_VIEW,
            PartnerPermission.UCN_DRAFT,
            PartnerPermission.UCN_EDIT,
            PartnerPermission.RECEIVE_NOTIFICATIONS,
            PartnerPermission.UCN_SUBMIT,
            PartnerPermission.UCN_DELETE,
            PartnerPermission.EDIT_PROFILE,
            PartnerPermission.EDIT_HQ_PROFILE,
            PartnerPermission.DSR_VIEW,
            PartnerPermission.DSR_ANSWER,
        ]),
        PartnerRole.READER: frozenset([
            PartnerPermission.VIEW_DASHBOARD,
            PartnerPermission.CFEI_VIEW,
            PartnerPermission.UCN_VIEW,
            PartnerPermission.DSR_VIEW,
        ]),
    },
    False: {  # INGO Country Profile
        PartnerRole.ADMIN: frozenset([
            PartnerPermission.VIEW_DASHBOARD,
            PartnerPermission.CFEI_VIEW,
            PartnerPermission.MANAGE_USERS,
            PartnerPermission.CFEI_PINNING,
            PartnerPermission.CFEI_ANSWER_SELECTION,
            PartnerPermission.UCN_VIEW,
            PartnerPermission.UCN_DRAFT,
            PartnerPermission.RECEIVE_NOTIFICATIONS,
            PartnerPermission.UCN_EDIT,
            PartnerPermission.UCN_SUBMIT,
            PartnerPermission.UCN_DELETE,
            PartnerPermission.EDIT_PROFILE,
            PartnerPermission.DSR_VIEW,
            PartnerPermission.DSR_ANSWER,
        ]),
        PartnerRole.EDITOR: frozenset([
            PartnerPermission.VIEW_DASHBOARD,
            PartnerPermission.CFEI_VIEW,
            PartnerPermission.CFEI_PINNING,
            PartnerPermission.CFEI_ANSWER_SELECTION,
            PartnerPermission.UCN_VIEW,
            PartnerPermission.UCN_DRAFT,
            PartnerPermission.UCN_EDIT,
            PartnerPermission.RECEIVE_NOTIFICATIONS,
            PartnerPermission.UCN_SUBMIT,
            PartnerPermission.UCN_DELETE,
            PartnerPermission.EDIT_PROFILE,
            PartnerPermission.DSR_VIEW,
            PartnerPermission.DSR_ANSWER,
        ]),
        PartnerRole.READER: frozenset([
            PartnerPermission.VIEW_DASHBOARD,
            PartnerPermission.CFEI_VIEW,
            PartnerPermission.UCN_VIEW,
            PartnerPermission.DSR_VIEW,
        ]),
    },
    None: {  # NGO
        PartnerRole.ADMIN: frozenset([
            PartnerPermission.REGISTER,
            PartnerPermission.VIEW_DASHBOARD,
            PartnerPermission.MANAGE_USERS,
            PartnerPermission.CFEI_VIEW,
            PartnerPermission.CFEI_PINNING,
            PartnerPermission.CFEI_ANSWER_SELECTION,
            PartnerPermission.UCN_VIEW,
            PartnerPermission.UCN_DRAFT,
            PartnerPermission.RECEIVE_NOTIFICATIONS,
            PartnerPermission.UCN_EDIT,
            PartnerPermission.UCN_SUBMIT,
            PartnerPermission.UCN_DELETE,
            PartnerPermission.EDIT_PROFILE,
            PartnerPermission.DSR_VIEW,
            PartnerPermission.DSR_ANSWER,
        ]),
        PartnerRole.EDITOR: frozenset([
            PartnerPermission.VIEW_DASHBOARD,
            PartnerPermission.CFEI_VIEW,
            PartnerPermission.CFEI_PINNING,
            PartnerPermission.CFEI_ANSWER_SELECTION,
            PartnerPermission.UCN_VIEW,
            PartnerPermission.UCN_DRAFT,
            PartnerPermission.UCN_EDIT,
            PartnerPermission.RECEIVE_NOTIFICATIONS,
            PartnerPermission.UCN_SUBMIT,
            PartnerPermission.UCN_DELETE,
            PartnerPermission.EDIT_PROFILE,
            PartnerPermission.DSR_VIEW,
            PartnerPermission.DSR_ANSWER,
        ]),
        PartnerRole.READER: frozenset([
            PartnerPermission.VIEW_DASHBOARD,
            PartnerPermission.CFEI_VIEW,
            PartnerPermission.UCN_VIEW,
            PartnerPermission.DSR_VIEW,
        ]),
    }
}

@@ -1047,32 +1047,88 @@
 ssion.UCN_VIEW,%0A
+            PartnerPermission.CFEI_SUBMIT_CONCEPT_NOTE,%0A
             Part
@@ -1144,32 +1144,32 @@
 sion.UCN_DRAFT,%0A
-
             Part
@@ -1957,32 +1957,88 @@
 _NOTIFICATIONS,%0A
+            PartnerPermission.CFEI_SUBMIT_CONCEPT_NOTE,%0A
             Part
@@ -3028,32 +3028,88 @@
 ion.UCN_SUBMIT,%0A
+            PartnerPermission.CFEI_SUBMIT_CONCEPT_NOTE,%0A
             Part
@@ -3704,32 +3704,88 @@
 ion.UCN_SUBMIT,%0A
+            PartnerPermission.CFEI_SUBMIT_CONCEPT_NOTE,%0A
             Part
@@ -4626,32 +4626,88 @@
 _NOTIFICATIONS,%0A
+            PartnerPermission.CFEI_SUBMIT_CONCEPT_NOTE,%0A
             Part
@@ -5249,32 +5249,32 @@
 sion.UCN_DRAFT,%0A
-
             Part
@@ -5289,32 +5289,88 @@
 ssion.UCN_EDIT,%0A
+            PartnerPermission.CFEI_SUBMIT_CONCEPT_NOTE,%0A
             Part

update permissions