import type { FormProps, FormItemRule } from 'element-plus'

export type FormSlot = {
  name: string
  alias: string
}

export type BasicFormItem = {
  id?: string
  label: string
  value: any
  name: string
  type: string
  placeholder?: string
  children?: Array<BasicFormItem>
  options?: Array<any>
  search?: boolean
  required?: boolean
  rules?: FormItemRule | FormItemRule[]
  span?: number
  props?: any
  events?: object
  request?: Function
  slots?: Array<FormSlot>
  notFormItem?: boolean
  hidden?: boolean
  extra?: any
  formItemProps?: object
}

export type AdvancedFormItem = {
  label: string
  group: BasicFormItem[]
  slots?: Array<FormSlot>
}

type Form = {
  props?: Partial<FormProps>
  route?: any
  span?: number
  disabled?: boolean
}

export type BasicForm = Form & {
  formItems: BasicFormItem[]
}

export type AdvancedForm = Form & {
  formItems: AdvancedFormItem[]
}

export interface ICRUD {
  create: (data: { [key: string]: any }) => Promise<any>
  update: (data: { [key: string]: any }) => Promise<any>
  delete: ({ id }: { id: string }) => Promise<any>
  deleteBatch?: ({ ids }: { ids: string }) => Promise<any>
  getList: (data: { pageSize: number; pageNo: number; [key: string]: any }) => Promise<any>
  getRecord?: ({ id }: { id: string }) => Promise<any>
}
