# _*_ coding : UTF-8 _*_
# @Time : 2025/02/28 18:00
# @UpdateTime : 2025/02/28 18:00
# @Author : sonder
# @File : generate.py
# @Software : PyCharm
# @Comment : 本程序
from typing import List

from pydantic import BaseModel, Field, ConfigDict
from pydantic.alias_generators import to_camel, to_snake

from schemas.common import BaseResponse, ListQueryResult


class TableInfo(BaseModel):
    """
    数据表信息模型
    """
    model_config = ConfigDict(alias_generator=to_snake)
    id: str = Field(default="", description="主键")
    table_name: str = Field(default="", description="表名称")
    table_comment: str = Field(default="", description="表注释")
    table_rows: int = Field(default=0, description="表行数")
    data_length: str = Field(default="", description="表大小")
    index_length: str = Field(default="", description="索引大小")
    create_time: str = Field(default="", description="创建时间")
    update_time: str = Field(default="", description="更新时间")


class GenerateTableInfo(BaseModel):
    """
    生成表信息模型
    """
    model_config = ConfigDict(alias_generator=to_snake)
    id: str = Field(default="", description="主键")
    table_name: str = Field(default="", description="表名称")
    table_comment: str = Field(default="", description="表注释")
    author: str = Field(default="", description="作者")
    prefix: str = Field(default="", description="api前缀")
    class_name: str = Field(default="", description="类名")
    remark: str = Field(default="", description="备注")
    description: str = Field(default="", description="描述")
    permission_id: str = Field(default="", description="权限ID")
    create_time: str = Field(default="", description="创建时间")
    update_time: str = Field(default="", description="更新时间")


class GetTableListResult(ListQueryResult):
    """
    获取数据表结果
    """
    result: List[TableInfo] = Field(default=None, description="响应数据")


class GetTablesListResponse(BaseResponse):
    """
    获取数据库表结果
    """
    data: TableInfo = Field(default=None, description="响应数据")


class AddGenerateInfoParams(BaseModel):
    """
    添加生成信息参数
    """
    table_name: str = Field(default="", description="表名称")
    table_comment: str = Field(default="", description="表注释")
    author: str = Field(default="", description="作者")
    prefix: str = Field(default="", description="api前缀")
    class_name: str = Field(default="", description="类名")
    remark: str = Field(default="", description="备注")
    permission_id: str = Field(default="", description="权限ID")
    description: str = Field(default="", description="备注")


class GenerateColumnInfo(BaseModel):
    """
    生成列信息
    """
    model_config = ConfigDict(alias_generator=to_snake)
    id: str = Field(default="", description="主键")
    table_id: str = Field(default="", description="表ID")
    table_name: str = Field(default="", description="表名称")
    table_comment: str = Field(default="", description="表注释")
    column_name: str = Field(default="", description="字段名称")
    column_comment: str = Field(default="", description="字段注释")
    column_type: str = Field(default="", description="字段类型")
    python_type: str = Field(default="", description="python类型")
    python_name: str = Field(default="", description="python名称")
    is_insert: bool = Field(default=True, description="是否插入")
    is_edit: bool = Field(default=True, description="是否编辑")
    is_list: bool = Field(default=True, description="是否列表")
    is_query: bool = Field(default=True, description="是否查询")
    query_way: str = Field(default="", description="查询方式")
    show_type: str = Field(default="", description="显示类型")
    is_required: bool = Field(default=False, description="是否必填")
    is_hide: bool = Field(default=False, description="是否隐藏")
    index: int = Field(default=0, description="索引")
    create_time: str = Field(default="", description="创建时间")
    update_time: str = Field(default="", description="更新时间")


class UpdateGenerateInfoParams(BaseModel):
    """
    更新生成信息参数
    """
    columns: List[GenerateColumnInfo] = Field(default=None, description="生成列信息")


class GetGenerateInfoResult(GenerateTableInfo):
    """
    获取生成信息结果
    """
    columns: List[GenerateColumnInfo] = Field(default=None, description="生成列信息")


class GetGenerateInfoListResult(ListQueryResult):
    """
    获取生成信息结果
    """
    result: List[GetGenerateInfoResult] = Field(default=[], description="响应数据")


class GetGenerateInfoResponse(BaseResponse):
    """
    获取生成信息结果
    """
    data: GetGenerateInfoResult = Field(default=None, description="响应数据")


class GetGenerateInfoListResponse(BaseResponse):
    """
    获取生成信息结果
    """
    data: GetGenerateInfoListResult = Field(default=[], description="响应数据")
