declare namespace API {
  /** 新增组件入参 */
  type FDComAlign = 'LEFT' | 'CENTER' | 'RIGHT'
  type FDComPosition = 'LEFT' | 'TOP'
  type FDDeaultValueFormat = 'PLAIN' | 'JSON' | 'XML'
  type FDValidItem = {
    expression: {
      body: string
      modifier: string
    }
    format: string
    message: string
  }
  /** 每个组件的expand参数 */
  type FD_EXPAND_INPUT = {
    /** 前缀 */
    prefix: string
    /** 后缀 */
    suffix: string
    /** 最大字符数 */
    maxChars: string
    /** 前缀icon */
    fIcon: string
    /** 后缀icon */
    bIcon: string
    limitVisible: boolean
  }
  type FD_EXPAND_AMOUNT_INPUT = FD_EXPAND_INPUT & {
    /** 单位 */
    unit: string
    /** 输入数字类型 */
    numberType: string
    /** 货币类型 */
    // currencyType: string
    /** 小数点位数 */
    decimalPlacesNumber: number | undefined
    /** 最小值 */
    min: number | undefined
    /** 最大值 */
    max: number | undefined
  }
  type FD_EXPAND_NUMBER_INPUT = FD_EXPAND_INPUT & {
    /** 输入功能类型 */
    featureType: 'NUMBER' | 'PERCENT'
    /** 单位 */
    unit: string
    /** 输入数字类型 */
    numberType: string
    /** 货币类型 */
    // currencyType: string
    /** 小数点位数 */
    decimalPlacesNumber: number | undefined
    /** 最小值 */
    min: number | undefined
    /** 最大值 */
    max: number | undefined
  }
  type FD_EXPAND_RADIO = {
    /** 数据来源类型: 用户输入/数据字典 */
    sourceType: 'USER_INPUT' | 'DICT'
    /** 用户输入内容 */
    userInput: { label: string; value: string; nanoid: string }[]
  }
  type FD_EXPAND_SELECT = {
    /** 数据来源类型: 用户输入/数据字典 */
    sourceType: 'USER_INPUT' | 'DICT'
    /** 用户输入内容 */
    userInput: { label: string; value: string; nanoid: string }[]
    multiple: boolean
  }
  type FD_EXPAND_OBJECT_PICKER = {
    label: string
    value: string
    child: string
    level: number
    animateLoading: boolean
  }
  type FD_EXPAND_FILE_PICKER = {
    accept?: string
    multiAcceptList: string[]
    fileSize: number
    sizeUnit: string
    listType: string
    btnText: string
    showTip: boolean
    multiple: boolean
    limit: number
    requiredLimit: number
    animateLoading: boolean
    hasTemplate: boolean
    templateTip: string
    templateList: any[]
  }
  type FD_EXPAND_DATETIME_PICKER = {
    dateType: string
    format: string
    periodStart: string
    periodEnd: string
  }
  type FD_EXPAND_TIME_PICKER = {
    format: string
    periodStart: string
    periodEnd: string
  }
  type FD_EXPAND_INPUT_MAP = {
    /** false:可选地点 true:不可能选地点, 只能打卡 */
    fixed: boolean
    centre: {
      site: Nullable<string>
      longitude: Nullable<string>
      latitude: Nullable<string>
      cityCode: Nullable<string>
      addressCode: Nullable<string>
    }
    distance: number
    periodStart: string
    periodEnd: string
  }
  type FD_EXPAND_BUTTON = {
    /** 按钮类型 */
    type: any
    /** 按钮文字 */
    text: string
    /** 按钮大小 */
    size: string
  }
  type FD_EXPAND_TITLE = {
    /** 标题 */
    title: string
    /** 描述 */
    desc: string
  }
  interface FD_COM {
    INPUT: API.FD_EXPAND_INPUT
    AMOUNT_INPUT: API.FD_EXPAND_AMOUNT_INPUT
    NUMBER_INPUT: API.FD_EXPAND_NUMBER_INPUT
    RADIO: API.FD_EXPAND_RADIO
    SELECT: API.FD_EXPAND_SELECT
    OBJECT_PICKER: API.FD_EXPAND_OBJECT_PICKER
    FILE_PICKER: API.FD_EXPAND_FILE_PICKER
    DATETIME_PICKER: API.FD_EXPAND_DATETIME_PICKER
    TIME_PICKER: API.FD_EXPAND_TIME_PICKER
    INPUT_MAP: API.FD_EXPAND_INPUT_MAP
    BUTTON: API.FD_EXPAND_BUTTON
    TITLE: API.FD_EXPAND_TITLE
  }
  type FD_EXPAND_INVOICE_PICKER = API.FD_EXPAND_FILE_PICKER & {
    /** 发票识别 */
    recognize: boolean
    /** 发票验真 */
    check: boolean
  }
  interface FD_COM_ENHANCE {
    INVOICE_PICKER: API.FD_EXPAND_INVOICE_PICKER
  }
  type FD_EXPAND_FINANCE_PICKER = API.FD_EXPAND_FILE_PICKER & {
    /** 填写形式 */
    fillType: string
    /** 文件解析类型 */
    fileParserType: string
    /** 是否开启解析 */
    enableParse: boolean
  }
  interface FD_COM_ENHANCE {
    FINANCE_PICKER: FD_EXPAND_FINANCE_PICKER
  }

  interface FDEventParams {
    runCode: Nullable<string>
    pluginId: Nullable<string>
    plugin?: Nullable<FD_Plugin>
    toastContent?: Nullable<string>
    toUrl?: Nullable<string>
  }
  interface FD_Header {
    key: string
    val: string
  }
  interface FD_QueryParameter {
    key: string
    val: string
  }

  interface FD_ActionConfiguration {
    body: string
    path: string
    headers: FD_Header[]
    httpMethod: string
    bodyFormData: any[]
    formDataType?: any
    queryParameters: FD_QueryParameter[]
  }
  interface FD_Plugin {
    pluginId: string
    pluginType: string
    label: string
    actionConfiguration: FD_ActionConfiguration
    datasource?: any
  }

  type FDDynamicTriggersItem = {
    eventType?: string
    runCode: Nullable<string>
    pluginId: Nullable<string>
    toastContent?: string
    onSuccess: Nullable<FDEventParams> & Nullable<{ apiResult?: any }>
    onError: Nullable<FDEventParams>
    plugin?: Nullable<FD_Plugin>
  }
  type FDDynamicTriggers = {
    [formId: string]: {
      [eventType: string]: FDDynamicTriggersItem
    }
  }

  type WidgetParams = {
    categoryId: string
    tenantId: string
    formId: string
    type: string
    label: {
      text: string
      align: FDComAlign
      position: FDComPosition
      visible: boolean
    }
    desc: string
    visible: boolean
    defaultValue: {
      format: FDesignDeaultValueFormat
      value: string
    }
    score?: number | string
    required: boolean
    placeholder: string
    span: number
    valid: FDValidItem[]
    expand?:
      | FD_COM['INPUT']
      | FD_COM['OBJECT_PICKER']
      | FD_COM['FILE_PICKER']
      | FD_COM['DATETIME_PICKER']
      | FD_COM['TIME_PICKER']
      | FD_COM['INPUT_MAP']
      | FD_COM['BUTTON']
      | Record<string, any>
    weight?: string
    widgetId?: string
    dynamicTriggers?: FDDynamicTriggersItem[]
  }
  type AddWidgetParams = Omit<WidgetParams, 'weight' | 'widgetId' | 'dynamicTriggers'>
  /** 新增组件返回结果 */
  type AddWidgetResult = {
    weight: string
    widgetId: string
    success: boolean
  }
  /** 组件列表 */
  type WidgetList = WidgetParams[]

  /** 分类树 */
  type CategoryTreeItem = {
    id: string
    parentId: string
    weight: number
    name: string
    value: string
    children: CategoryTreeItem[]
  }
  type CategoryTree = CategoryTreeItem[]

  type Category = {
    categoryId: string
    categoryName: string
    gigType: string
    parentId: string
    weight: number
    categoryValue: string
  }

  /** 组件排序入参 */
  type WidgetSortParams = {
    widgetId: string
    beforePosition: string
    afterPosition: string
  }
}
