/**
 * KRA - Kratos Admin Type Definitions
 */

// Common pagination params
export interface PageParams {
  page: number;
  pageSize: number;
}

// Common pagination response
export interface PageResult<T> {
  list: T[];
  total: number;
  page: number;
  pageSize: number;
}

// Common ID params
export interface IdParams {
  ID: number;
}

export interface IdsParams {
  ids: number[];
}

// Base entity with timestamps
export interface BaseEntity {
  ID: number;
  CreatedAt: string;
  UpdatedAt: string;
  DeletedAt?: string | null;
}

// User related types
export interface UserInfo extends BaseEntity {
  uuid: string;
  userName: string;
  nickName: string;
  sideMode: string;
  headerImg: string;
  baseColor: string;
  activeColor: string;
  authorityId: number;
  phone: string;
  email: string;
  enable: number;
  authority: Authority;
  authorities: Authority[];
  originSetting?: AppConfig;
}

// Authority/Role types
export interface Authority extends BaseEntity {
  authorityId: number;
  authorityName: string;
  parentId: number;
  dataAuthorityId?: Authority[];
  children?: Authority[];
  menus?: MenuItem[];
  defaultRouter: string;
}

// Menu types
export interface MenuItem extends BaseEntity {
  parentId: number;
  path: string;
  name: string;
  hidden: boolean;
  component: string;
  sort: number;
  meta: MenuMeta;
  authoritys?: Authority[];
  children?: MenuItem[];
  parameters?: MenuParameter[];
  menuBtn?: MenuButton[];
  btns?: Record<string, number>;
}

export interface MenuMeta {
  activeName?: string;
  keepAlive: boolean;
  defaultMenu: boolean;
  title: string;
  icon: string;
  closeTab: boolean;
}

export interface MenuParameter {
  ID: number;
  type: string;
  key: string;
  value: string;
}

export interface MenuButton {
  ID: number;
  name: string;
  desc: string;
}

// API types
export interface ApiInfo extends BaseEntity {
  path: string;
  description: string;
  apiGroup: string;
  method: string;
}

// Dictionary types
export interface Dictionary extends BaseEntity {
  name: string;
  type: string;
  status: boolean;
  desc: string;
  sysDictionaryDetails?: DictionaryDetail[];
}

export interface DictionaryDetail extends BaseEntity {
  label: string;
  value: number;
  status: boolean;
  sort: number;
  sysDictionaryID: number;
}

// System params types
export interface SysParams extends BaseEntity {
  key: string;
  value: string;
  desc: string;
}

// Operation record types
export interface OperationRecord extends 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;
}

// File upload types
export interface FileInfo extends BaseEntity {
  name: string;
  url: string;
  tag: string;
  key: string;
}

// Customer example types
export interface Customer extends BaseEntity {
  customerName: string;
  customerPhoneData: string;
  sysUserID: number;
  sysUserAuthorityID: number;
  sysUser?: UserInfo;
}

// App config types
export interface AppConfig {
  weakness?: boolean;
  grey?: boolean;
  primaryColor?: string;
  showTabs?: boolean;
  darkMode?: 'light' | 'dark' | 'auto';
  layout_side_width?: number;
  layout_side_collapsed_width?: number;
  layout_side_item_height?: number;
  show_watermark?: boolean;
  side_mode?: 'normal' | 'head' | 'combination';
  transition_type?: string;
  global_size?: 'small' | 'middle' | 'large';
}

// System config types
export interface SystemConfig {
  system: {
    env: string;
    addr: string;
    dbType: string;
    ossType: string;
    useMultipoint: boolean;
    useRedis: boolean;
    lowerCaseTableName: boolean;
    routerPrefix: string;
  };
  jwt: {
    signingKey: string;
    expiresTime: string;
    bufferTime: string;
    issuer: string;
  };
  captcha: {
    keyLong: number;
    imgWidth: number;
    imgHeight: number;
    openCaptcha: number;
    openCaptchaTimeOut: number;
  };
  email?: {
    to: string;
    port: number;
    from: string;
    host: string;
    isSSL: boolean;
    secret: string;
    nickname: string;
  };
}
