export type ApiResponse<T> = {
  code: number
  data: T
  msg: string
}

export type BaseEntity = {
  ID: number
  CreatedAt?: string
  UpdatedAt?: string
}

export type Authority = {
  authorityId: number
  authorityName: string
  parentId?: number | null
  defaultRouter?: string
  children?: Authority[]
}

export type PagePayload<T> = {
  list: T[]
  total: number
  page: number
  pageSize: number
}

export type UserInfo = BaseEntity & {
  uuid?: string
  userName: string
  nickName: string
  headerImg?: string
  authorityId?: number
  authority?: Authority
  authorities?: Authority[]
  phone?: string
  email?: string
  enable?: number
  originSetting?: Record<string, unknown>
}

export type MenuMeta = {
  title: string
  icon?: string
  keepAlive?: boolean
  closeTab?: boolean
  defaultMenu?: boolean
  activeName?: string
  transitionType?: string
}

export type MenuNode = BaseEntity & {
  parentId: number
  path: string
  name: string
  hidden?: boolean
  component: string
  sort: number
  meta: MenuMeta
  menuBtn?: Array<{ ID: number; name: string; desc?: string }>
  btns?: Record<string, number>
  children?: MenuNode[]
}

export type AppMenu = MenuNode & {
  fullPath: string
  fullPathKey: string
  parentName?: string
  children?: AppMenu[]
}

export type LoginResult = {
  user: UserInfo
  token: string
  expiresAt: number
}

export type CaptchaInfo = {
  captchaId: string
  picPath: string
  captchaLength: number
  openCaptcha: boolean
}

export type ApiRecord = BaseEntity & {
  path: string
  description: string
  apiGroup: string
  method: string
}

export type Dictionary = BaseEntity & {
  name: string
  type: string
  status?: boolean | null
  desc?: string
  parentID?: number | null
  children?: Dictionary[]
}

export type DictionaryDetail = BaseEntity & {
  label: string
  value: string
  extend?: string
  status?: boolean | null
  sort?: number
  sysDictionaryID: number
  parentID?: number | null
  level?: number
  path?: string
  children?: DictionaryDetail[]
}

export type SysParam = BaseEntity & {
  name: string
  key: string
  value: string
  desc?: string
}

export type LoginLog = BaseEntity & {
  username: string
  ip: string
  status: boolean
  errorMessage?: string
  agent?: string
}

export type OperationRecord = BaseEntity & {
  ip: string
  method: string
  path: string
  status: number
  latency?: string
  agent?: string
  error_message?: string
  body?: string
  resp?: string
  user_id?: number
  user?: UserInfo
}

export type ApiTokenRecord = BaseEntity & {
  userId: number
  authorityId: number
  token?: string
  status: boolean
  expiresAt: string
  remark?: string
  user?: UserInfo
}

export type SysErrorRecord = BaseEntity & {
  form?: string | null
  info?: string | null
  level?: string
  solution?: string | null
  status?: string
}

export type ModuleStatus = 'ready' | 'partial' | 'planned'

export type ModuleDescriptor = {
  name: string
  title: string
  summary: string
  group: string
  status: ModuleStatus
  features: string[]
  endpoints: string[]
}
