import { ProblemPhaseKey, ProblemSeverityKey } from './type'

/**
 * Error
 * 错误对象
 */
export interface ApiError {
  /**
   * @description error code, 错误码
   * @format int32
   * @example 1000001001
   */
  code: number

  /**
   * @description error title, 错误标题
   * @example "USER_NAME_EMPTY"
   */
  title: string

  /**
   * @description error description, 错误描述
   * @example "username should not be empty"
   */
  description?: string

  /**
   * @description error description2, 错误描述(第二语言)
   * @example "用户名不可以为空"
   */
  description2?: string

  /**
   * @description whether this error is deprecated
   * @example true|false
   */
  deprecated?: boolean

  /**
   * @description field name, 字段
   * @example "name"
   */
  field?: string

  /**
   * @description field path, 字段路径
   * @example "user.name"
   */
  path?: string

  /**
   * @description input value(which rejected),输入值(被拒绝的)
   * @example "Jake.Bush"
   */
  rejectedValue?: string

  /**
   * @description tips, 使用提示
   * @example "价格必须是正数:1000.12"
   */
  tips?: string

  /**
   * @description constraint rule, 校验规则
   * @example "POSITIVE|NOT_EMPTY|REG_EXP"
   */
  constraint?: string

  /**
   * @description phase of the error thrown, 错误阶段
   * @example "DOMAIN:表示在领域层"
   */
  phase?: ProblemPhaseKey

  /**
   * @description severity of the error, 错误程度
   * @example "ERROR: 表示业务中断"
   */
  severity?: ProblemSeverityKey

  /**
   * @description business domain, 领域
   * @example "order"
   */
  domain?: string

  /**
   * @description 其他属性(KV), flat to normal fields refer to the problem details of hope/spring
   * @example "扩展属性, Key-Value 对"
   */
  properties?: Record<string, any>
}

/**
 * List of errors
 * 错误对象列表
 */
export type ApiErrors = ApiError[]

/**
 * 分页查询对象
 * Page request parameters
 */
export interface PageRequest {
  /**
   * @description Zero-based page index (0..N)
   * @example 42
   */
  page: number

  /**
   * @description The size of the page to be returned, default 20, max: 1024
   * @example 10
   */
  size: number

  /**
   * @description infinite scroll load this is the last offset if any key specific
   * @example "101234"
   */
  offset?: string

  /**
   * @description `Sorting criteria in the format: property,(asc|desc). Default sort order is ascending. Multiple sort criteria are supported.`
   * @example `id,desc`
   */
  sort?: string[]
}

/**
 * 分页数据集
 */
export interface PageableResult<T> {
  /**
   * @description page index, 当前页码 (from Zero 0)
   */
  pageIndex: number

  /**
   * @description page size, 本页对象数量
   */
  pageSize: number

  /**
   * @description total count, 总数
   */
  totalCount: number

  /**
   * @description total page number, 总页数
   */
  totalPage: number

  /**
   * @description data payload 数据集
   */
  data: T[]
}
