from django.db.models.signals import post_migrate
from django.dispatch import receiver
from django.contrib.auth.models import Group

from tickets.models import TicketList


@receiver(post_migrate)
def create_initial_ticket_lists(sender, **kwargs):
    if sender.name == 'tickets':
        # METASERVICE
        ## ADMIN
        TicketList.objects.get_or_create(pk=1101, name='Активация партнеров (NEG_REQUEST)', group=Group.objects.get(name='METASERVICE-ADMIN'))
        TicketList.objects.get_or_create(pk=1102, name='Права в сервисе (ACCESS_REQUEST)', group=Group.objects.get(name='METASERVICE-ADMIN'))
        TicketList.objects.get_or_create(pk=1103, name='Проверка документов (ST_REQUEST)', group=Group.objects.get(name='METASERVICE-ADMIN'))

        ## SUPERVISOR
        TicketList.objects.get_or_create(pk=1201, name='Активность пользователей (ST_REQUEST)', group=Group.objects.get(name='METASERVICE-SUPERVISOR'))
        TicketList.objects.get_or_create(pk=1202, name='Оперативный доступ (ST_REQUEST)', group=Group.objects.get(name='METASERVICE-SUPERVISOR'))
        TicketList.objects.get_or_create(pk=1203, name='Оперативный доступ экстра (ACCESS_REQUEST)', group=Group.objects.get(name='METASERVICE-SUPERVISOR'))
        TicketList.objects.get_or_create(pk=1204, name='Права сервиса (ST_REQUEST)', group=Group.objects.get(name='METASERVICE-SUPERVISOR'))
        TicketList.objects.get_or_create(pk=1205, name='Проверка документов (ST_REQUEST)', group=Group.objects.get(name='METASERVICE-SUPERVISOR'))

        ## SUPPORT
        TicketList.objects.get_or_create(pk=1301, name='Входящие обычные заявки (ST_REQUEST)', group=Group.objects.get(name='METASERVICE-SUPPORT'))
        TicketList.objects.get_or_create(pk=1302, name='Заявки на услуги сервиса (SERVICE_REQUEST)', group=Group.objects.get(name='METASERVICE-SUPPORT'))

        ## TECHSUPPORT
        TicketList.objects.get_or_create(pk=1401, name='Входящие технические заявки (ST_REQUEST)', group=Group.objects.get(name='METASERVICE-TECHSUPPORT'))

        # PARTNER
        ## ADMIN
        TicketList.objects.get_or_create(pk=2101, name='Документы исполнителей (ST_REQUEST)', group=Group.objects.get(name='PARTNER-ADMIN'))
        TicketList.objects.get_or_create(pk=2102, name='Документы ресурсов (ST_REQUEST)', group=Group.objects.get(name='PARTNER-ADMIN'))
        TicketList.objects.get_or_create(pk=2103, name='Права в партнерке (ACCESS_REQUEST)', group=Group.objects.get(name='PARTNER-ADMIN'))
        
        ## SUPERVISOR
        TicketList.objects.get_or_create(pk=2201, name='Активность внутри партнера (ST_REQUEST)', group=Group.objects.get(name='PARTNER-SUPERVISOR'))
        TicketList.objects.get_or_create(pk=2202, name='Документы исполнителей (ST_REQUEST)', group=Group.objects.get(name='PARTNER-SUPERVISOR'))
        TicketList.objects.get_or_create(pk=2203, name='Документы ресурсов (ST_REQUEST)', group=Group.objects.get(name='PARTNER-SUPERVISOR'))
        TicketList.objects.get_or_create(pk=2204, name='Доступ внутри партнера (ST_REQUEST)', group=Group.objects.get(name='PARTNER-SUPERVISOR'))
        TicketList.objects.get_or_create(pk=2205, name='Оперативный доступ (ST_REQUEST)', group=Group.objects.get(name='PARTNER-SUPERVISOR'))
        TicketList.objects.get_or_create(pk=2206, name='Оперативный доступ экстра (ST_REQUEST)', group=Group.objects.get(name='PARTNER-SUPERVISOR'))
        TicketList.objects.get_or_create(pk=2207, name='Ручное подтверждение заявок (ACCESS-REQUEST)', group=Group.objects.get(name='PARTNER-SUPERVISOR'))
        
        ## TECHSUPPORT
        TicketList.objects.get_or_create(pk=2401, name='Входящие технические заявки (ST_REQUEST)', group=Group.objects.get(name='PARTNER-TECHSUPPORT'))