# _*_ coding : UTF-8 _*_
# @Time : 2025/02/21 03:37
# @UpdateTime : 2025/02/21 03:37
# @Author : sonder
# @File : generate.py
# @Software : PyCharm
# @Comment : 本程序
from tortoise import fields

from models.common import BaseModel


class GenerateInfo(BaseModel):
    """
    代码生成表模型
    """
    table_name = fields.CharField(max_length=255, default="", description="表名称", source_field="table_name")
    table_comment = fields.CharField(max_length=255, default="", description="表注释", source_field="table_comment")
    class_name = fields.CharField(max_length=255, default="", description="类名", source_field="class_name")
    author = fields.CharField(max_length=255, default="", description="作者", source_field="author")
    remark = fields.TextField(default="", description="备注", null=True, source_field="remark")
    permission_id = fields.CharField(max_length=255, default="", description="权限ID", source_field="permission_id")
    prefix = fields.CharField(max_length=255, default="", description="api前缀", source_field="prefix")
    description = fields.TextField(default="", description="描述", null=True, source_field="description")

    class Meta:
        table = "generate_info"
        table_description = "代码生成表"


class GenerateColumn(BaseModel):
    """
    代码生成列模型
    """
    table = fields.ForeignKeyField("models.GenerateInfo", related_name="columns", description="表",
                                   source_field="table_id")
    index = fields.IntField(default=0, description="索引", source_field="index")
    column_name = fields.CharField(max_length=255, default="", description="字段名称", source_field="column_name")
    column_comment = fields.CharField(max_length=255, default="", description="字段注释", source_field="column_comment")
    column_type = fields.CharField(max_length=255, default="", description="字段类型", source_field="column_type")
    python_type = fields.CharField(max_length=255, default="", description="python类型", source_field="python_type")
    python_name = fields.CharField(max_length=255, default="", description="python名称", source_field="python_name")
    is_insert = fields.BooleanField(default=True, description="是否插入", source_field="is_insert")
    is_edit = fields.BooleanField(default=True, description="是否编辑", source_field="is_edit")
    is_list = fields.BooleanField(default=True, description="是否列表", source_field="is_list")
    is_query = fields.BooleanField(default=True, description="是否查询", source_field="is_query")
    is_required = fields.BooleanField(default=False, description="是否必填", source_field="is_required")
    is_hide = fields.BooleanField(default=False, description="是否隐藏", source_field="is_hide")
    query_way = fields.CharField(max_length=255, default="", description="查询方式", source_field="query_way")
    show_type = fields.CharField(max_length=255, default="", description="显示类型", source_field="show_type")

    class Meta:
        table = "generate_column"
        table_description = "代码生成列"
