from pydantic import BaseModel, Field
from typing import Optional, List, Dict, Any


# ==================== Token相关模型 ====================

class TokenData(BaseModel):
    """Token数据"""
    token: str = Field(..., description="token")
    projectId: int = Field(..., description="见知项目Id")
    projectNo: str = Field(..., description="项目编号")
    entityName: str = Field(..., description="项目名称")
    analysisType: int = Field(0, description="分析类型")


class GetTokenResponse(BaseModel):
    """获取Token响应"""
    code: str = Field("200", description="返回码")
    data: Optional[TokenData] = Field(None, description="返回数据")
    message: str = Field("create.token.success", description="返回消息")
    status: str = Field("200", description="状态")
    successResponse: bool = Field(True, description="是否成功响应")


# ==================== 文件上传相关模型 ====================

class AccountInfo(BaseModel):
    """账户信息"""
    bank: str = Field(..., description="银行")
    accountName: str = Field(..., description="账户名称")
    accountNo: str = Field(..., description="账号")
    currency: str = Field(..., description="币种")


class UploadLogItem(BaseModel):
    """上传日志项"""
    accountNoList: List[str] = Field(default=[], description="账号列表")
    bankName: str = Field(..., description="银行名称")
    dataTypeInfo: List[str] = Field(default=[], description="数据类型信息")
    downloadFileName: str = Field(..., description="下载文件名")
    enterpriseNameList: List[str] = Field(default=[], description="企业名称列表")
    filePackageId: str = Field(..., description="文件包ID")
    fileSize: int = Field(..., description="文件大小")
    fileUploadBy: int = Field(..., description="上传者ID")
    fileUploadByUserName: str = Field(..., description="上传者用户名")
    fileUploadTime: str = Field(..., description="上传时间")
    leId: int = Field(..., description="企业ID")
    logId: int = Field(..., description="日志ID")
    logMeta: str = Field(..., description="日志元数据")
    logType: str = Field(..., description="日志类型")
    loginLeId: int = Field(..., description="登录企业ID")
    realBankName: str = Field(..., description="真实银行名称")
    rows: int = Field(0, description="行数")
    source: str = Field(..., description="来源")
    status: int = Field(-5, description="状态值")
    templateName: str = Field(..., description="模板名称")
    totalRecords: int = Field(0, description="总记录数")
    trxDateEndId: int = Field(..., description="交易结束日期ID")
    trxDateStartId: int = Field(..., description="交易开始日期ID")
    uploadFileName: str = Field(..., description="上传文件名")
    uploadStatusDesc: str = Field(..., description="上传状态描述")


class UploadFileResponse(BaseModel):
    """上传文件响应"""
    code: str = Field("200", description="返回码")
    data: Optional[Dict[str, Any]] = Field(None, description="返回数据")
    status: str = Field("200", description="状态")
    successResponse: bool = Field(True, description="是否成功响应")


# ==================== 检查解析状态相关模型 ====================

class PendingItem(BaseModel):
    """待处理项"""
    accountNoList: List[str] = Field(default=[], description="账号列表")
    bankName: str = Field(..., description="银行名称")
    dataTypeInfo: List[str] = Field(default=[], description="数据类型信息")
    downloadFileName: str = Field(..., description="下载文件名")
    enterpriseNameList: List[str] = Field(default=[], description="企业名称列表")
    filePackageId: str = Field(..., description="文件包ID")
    fileSize: int = Field(..., description="文件大小")
    fileUploadBy: int = Field(..., description="上传者ID")
    fileUploadByUserName: str = Field(..., description="上传者用户名")
    fileUploadTime: str = Field(..., description="上传时间")
    isSplit: int = Field(0, description="是否分割")
    leId: int = Field(..., description="企业ID")
    logId: int = Field(..., description="日志ID")
    logMeta: str = Field(..., description="日志元数据")
    logType: str = Field(..., description="日志类型")
    loginLeId: int = Field(..., description="登录企业ID")
    lostHeader: List[str] = Field(default=[], description="丢失的头部")
    realBankName: str = Field(..., description="真实银行名称")
    rows: int = Field(0, description="行数")
    source: str = Field(..., description="来源")
    status: int = Field(-5, description="状态值")
    templateName: str = Field(..., description="模板名称")
    totalRecords: int = Field(0, description="总记录数")
    trxDateEndId: int = Field(..., description="交易结束日期ID")
    trxDateStartId: int = Field(..., description="交易开始日期ID")
    uploadFileName: str = Field(..., description="上传文件名")
    uploadStatusDesc: str = Field(..., description="上传状态描述")


class CheckParseStatusResponse(BaseModel):
    """检查解析状态响应"""
    code: str = Field("200", description="返回码")
    data: Optional[Dict[str, Any]] = Field(None, description="返回数据，包含parsing和pendingList")
    status: str = Field("200", description="状态")
    successResponse: bool = Field(True, description="是否成功响应")


# ==================== 银行流水相关模型 ====================

class BankStatementItem(BaseModel):
    """银行流水项"""
    accountId: int = Field(0, description="账号ID")
    accountMaskNo: str = Field(..., description="账号")
    accountingDate: str = Field(..., description="记账日期")
    accountingDateId: int = Field(..., description="记账日期ID")
    archivingFlag: int = Field(0, description="归档标志")
    attachments: int = Field(0, description="附件数")
    balanceAmount: float = Field(..., description="余额")
    bank: str = Field(..., description="银行")
    bankComments: str = Field("", description="银行注释")
    bankStatementId: int = Field(..., description="流水ID")
    bankTrxNumber: str = Field(..., description="银行交易号")
    batchId: int = Field(..., description="批次ID")
    cashType: str = Field("1", description="现金类型")
    commentsNum: int = Field(0, description="评论数")
    crAmount: float = Field(0, description="贷方金额")
    createDate: str = Field(..., description="创建日期")
    createdBy: str = Field("902001", description="创建人")
    cretNo: str = Field(..., description="证件号")
    currency: str = Field("CNY", description="币种")
    customerAccountMaskNo: str = Field(..., description="客户账号")
    customerBank: str = Field("", description="客户银行")
    customerId: int = Field(-1, description="客户ID")
    customerName: str = Field(..., description="客户名称")
    customerReference: str = Field("", description="客户参考")
    customerCertNo: str = Field("", description="客户证件号")
    customerSocialCreditCode: str = Field("", description="客户统一社会信用代码")
    downPaymentFlag: int = Field(0, description="首付标志")
    drAmount: float = Field(0, description="借方金额")
    exceptionType: str = Field("", description="异常类型")
    groupId: int = Field(0, description="项目ID")
    internalFlag: int = Field(0, description="内部标志")
    leId: int = Field(..., description="企业ID")
    leName: str = Field(..., description="企业名称")
    overrideBsId: int = Field(0, description="覆盖流水ID")
    paymentMethod: str = Field("", description="支付方式")
    sourceCatalogId: int = Field(0, description="来源目录ID")
    split: int = Field(0, description="分割")
    subBankstatementId: int = Field(0, description="子流水ID")
    toDoFlag: int = Field(0, description="待办标志")
    transAmount: float = Field(..., description="交易金额")
    transFlag: str = Field("P", description="交易标志")
    transTypeId: int = Field(0, description="交易类型ID")
    transformAmount: int = Field(0, description="转换金额")
    transformCrAmount: int = Field(0, description="转换贷方金额")
    transformDrAmount: int = Field(0, description="转换借方金额")
    transfromBalanceAmount: int = Field(0, description="转换余额")
    trxBalance: int = Field(0, description="交易余额")
    trxDate: str = Field(..., description="交易日期")
    uploadSequnceNumber: int = Field(..., description="上传序列号")
    userMemo: str = Field(..., description="用户备注")


class GetBankStatementResponse(BaseModel):
    """获取银行流水响应"""
    code: str = Field("200", description="返回码")
    data: Optional[Dict[str, Any]] = Field(None, description="返回数据，包含bankStatementList和totalCount")
    status: str = Field("200", description="状态")
    successResponse: bool = Field(True, description="是否成功响应")


# ==================== 其他响应模型 ====================

class FetchInnerFlowResponse(BaseModel):
    """拉取行内流水响应"""
    code: str = Field("200", description="返回码")
    data: Optional[Dict[str, Any]] = Field(None, description="返回数据")
    status: str = Field("200", description="状态")
    successResponse: bool = Field(True, description="是否成功响应")


class DeleteFilesResponse(BaseModel):
    """删除文件响应"""
    code: str = Field("200", description="返回码")
    data: Optional[Dict[str, str]] = Field(None, description="返回数据")
    status: str = Field("200", description="状态")
    successResponse: bool = Field(True, description="是否成功响应")
