# Generated by Django 5.2.4 on 2025-07-14 03:50

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 lzkb.const import CONFIG

default_password = CONFIG.get('DEFAULT_PASSWORD', 'ChangeMe@1234!')


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, db_index=True, max_length=254, null=True, unique=True, verbose_name='邮箱')),
                ('phone', models.CharField(db_index=True, default='', max_length=20, verbose_name='电话')),
                ('nick_name', models.CharField(db_index=True, max_length=150, unique=True, verbose_name='昵称')),
                ('username', models.CharField(db_index=True, 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(db_index=True, default='LOCAL', max_length=10, verbose_name='来源')),
                ('is_active', models.BooleanField(db_index=True, default=True)),
                ('language', models.CharField(default=None, max_length=10, null=True, verbose_name='语言')),
                ('create_time', models.DateTimeField(auto_now_add=True, db_index=True, null=True, verbose_name='创建时间')),
                ('update_time', models.DateTimeField(auto_now=True, db_index=True, null=True, verbose_name='修改时间')),
            ],
            options={
                'db_table': 'user',
            },
        ),
        migrations.RunPython(insert_default_data)
    ]
