# Generated by Django 5.2.3 on 2025-06-23 02:14

import uuid_utils.compat
from django.db import migrations, models

from common.constants.permission_constants import RoleConstants
from common.utils.common import password_encrypt
from maxkb.const import CONFIG

default_password = CONFIG.get('default_password', 'MaxKB@123..')

def insert_default_data(apps, schema_editor):
    UserModel = apps.get_model('users', 'User')
    UserModel.objects.create(id='f0dd8f71-e4ee-11ee-8c84-a8a1595801ab', email='', username='admin',
                             nick_name="系统管理员",
                             password=password_encrypt(default_password),
                             role=RoleConstants.ADMIN.name,
                             is_active=True)


class Migration(migrations.Migration):
    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='User',
            fields=[
                ('id', models.UUIDField(default=uuid_utils.compat.uuid7, editable=False, primary_key=True, serialize=False, verbose_name='主键id')),
                ('email', models.EmailField(blank=True, max_length=254, null=True, unique=True, verbose_name='邮箱')),
                ('phone', models.CharField(default='', max_length=20, verbose_name='电话')),
                ('nick_name', models.CharField(max_length=150, unique=True, verbose_name='昵称')),
                ('username', models.CharField(max_length=150, unique=True, verbose_name='用户名')),
                ('password', models.CharField(max_length=150, verbose_name='密码')),
                ('role', models.CharField(max_length=150, verbose_name='角色')),
                ('source', models.CharField(default='LOCAL', max_length=10, verbose_name='来源')),
                ('is_active', models.BooleanField(default=True)),
                ('language', models.CharField(default=None, max_length=10, null=True, verbose_name='语言')),
                ('create_time', models.DateTimeField(auto_now_add=True, null=True, verbose_name='创建时间')),
                ('update_time', models.DateTimeField(auto_now=True, null=True, verbose_name='修改时间')),
            ],
            options={
                'db_table': 'user',
            },
        ),
        migrations.RunPython(insert_default_data)
    ]
