#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# 初始化

from django_base_ai.system.views.api_white_list import ApiWhiteListInitSerializer
from django_base_ai.system.views.dept import DeptInitSerializer
from django_base_ai.system.views.dictionary import DictionaryInitSerializer
from django_base_ai.system.views.menu import MenuInitSerializer
from django_base_ai.system.views.role import RoleInitSerializer
from django_base_ai.system.views.system_config import SystemConfigInitSerializer
from django_base_ai.system.views.tags import TagsInitSerializer
from django_base_ai.system.views.user import UsersInitSerializer
from django_base_ai.utils.core_initialize import CoreInitialize


class Initialize(CoreInitialize):
    def init_dept(self):
        """
        初始化部门信息
        """
        self.init_base(DeptInitSerializer, unique_fields=["name", "parent", "key"])

    def init_role(self):
        """
        初始化角色信息
        """
        self.init_base(RoleInitSerializer, unique_fields=["key"])

    def init_users(self):
        """
        初始化用户信息
        """
        self.init_base(UsersInitSerializer, unique_fields=["username"])

    def init_tags(self):
        """
        初始化标签
        """
        self.init_base(TagsInitSerializer, unique_fields=["name"])

    def init_menu(self):
        """
        初始化菜单信息
        """
        self.init_base(MenuInitSerializer, unique_fields=["name", "component"])

    def init_api_white_list(self):
        """
        初始API白名单
        """
        self.init_base(
            ApiWhiteListInitSerializer,
            unique_fields=[
                "url",
                "method",
            ],
        )

    def init_dictionary(self):
        """
        初始化字典表
        """
        self.init_base(
            DictionaryInitSerializer,
            unique_fields=[
                "value",
                "parent",
            ],
        )

    def init_system_config(self):
        """
        初始化系统配置表
        """
        self.init_base(
            SystemConfigInitSerializer,
            unique_fields=[
                "key",
                "parent",
            ],
        )

    def run(self):
        self.init_dept()
        self.init_role()
        self.init_users()
        self.init_tags()
        self.init_menu()
        self.init_api_white_list()
        self.init_dictionary()
        self.init_system_config()


if __name__ == "__main__":
    Initialize(app="admin.system").run()
