/**
 * 自动化调用参数结构定义
 */
declare class AutomaticParams {
    /**
     * 调用的自动化标识符
     */
    automaticId: string;
    /**
     * 调用自动化传递的参数
     */
    args: Array<any>;
    /**
     * 是否展示系统的loading
     */
    withoutTimeoutLoading: Boolean;
    /**
     * 自动化的上下文sourceId
     */
    sourceId: string;
}

/**
 * 设置字段值参数结构对象
 */
declare class FieldValueParam {
    /**
     * 字段标识符
     */
    field: string;
    /**
     * 字段值
     */
    value: any;
}

/**
 * 字段记录结构
 */
declare class FormField implements Record<string, any> {
    id: string;
}

/**
 * 表单记录结构
 */
declare class FormRecord implements Record<string, any> {
    id: string;
}

/**
 * 表单变更推送数据
 */
declare class RecordUpdateEvent extends FormRecord {
}

/**
 * 字段表更事件推送数据
 */
declare class FieldChangeEvent {
    /**
     * 变更的字段
     */
    field: FormField;
    /**
     * 变更后的表单数据
     */
    record: FormRecord;
}

declare type RECORD_RELOAD_EVENT_TYPE =
    'UserRefresh'
    | 'Automatic.OutputRecordFormRefresh'
    | 'Automatic.SSERecordFormRefresh'
    | 'RecordTaskListUpdate'
    | 'BpmnProcessChange'
    | 'BpmnTaskChange';

/**
 * 表单刷新事件推送数据
 */
declare class RecordReloadEvent {
    /**
     * 触发类型
     */
    type: RECORD_RELOAD_EVENT_TYPE | String;
    /**
     * 变更后的表单数据
     */
    record: FormRecord;
}

declare type EVENT_TYPE =
    'rpc-ready'
    | 'rpc-reload'
    | 'automatic-event'
    | 'record-reload'
    | 'record-updated'
    | 'field-change'
    | 'print-page';

/**
 * 系统推送事件监听
 * @see [说明文档] {@link https://next.informat.cn/doc/index.html#/website/event-service }
 */
interface eventService {

    /**
     * 添加事件监听
     * @param type
     * @param handler
     */
    onEvent(type: EVENT_TYPE | string, handler: (data: string | RecordUpdateEvent | FieldChangeEvent | RecordReloadEvent | Object | any) => void): void;

    /**
     * 移除事件监听
     * @param type
     */
    offEvent(type: EVENT_TYPE | string): void;

    /**
     * 添加单次事件监听
     * @param type
     * @param handler
     */
    onceEvent(type: EVENT_TYPE | string, handler: (data: string | RecordUpdateEvent | FieldChangeEvent | Object | any) => void): void;
}

/**
 * 系统确认框配置项
 */
declare class SystemConfirmOption {
    /**
     * 对话框标题
     */
    title: string;
    /**
     * 提示内容（必填）
     */
    content: string;
    /**
     * 窗口距顶距离，默认(15vh)
     */
    dialogTop: string;
    /**
     * 窗口高度
     */
    dialogHeight: string;
    /**
     * 窗口宽度，默认(400px)
     */
    dialogWidth: string;
    /**
     * 提示内容水平对齐方式
     *
     * |值|描述|
     * |left|居左|
     * |center|居中(默认)|
     * |right|居右|
     * |justify|两端对齐|
     */
    horizontalAlign: string | 'left' | 'center' | 'right' | 'justify';
    /**
     * 提示内容垂直对齐方式
     *
     * |值|描述|
     * |top|顶部|
     * |center|居中(默认)|
     * |bottom|底部|
     */
    verticalAlign: string | 'top' | 'center' | 'bottom';
    /**
     * 是否展示取消按钮，默认(true)
     */
    showCancel: boolean;
    /**
     * 取消按钮文字，默认(取消)
     */
    cancelText: string;
    /**
     * 确认按钮文字，默认(确认)
     */
    confirmText: string;
}

/**
 * 图片预览的图片项
 */
declare class PreviewImageItem {
    /**
     * 图片的ID，可选参数
     */
    id?: string;
    /**
     * 图片的名称，可选参数
     */
    name?: string;
    /**
     * 图片地址，必填参数
     */
    src: string;
}

/**
 * 图片预览配置项
 */
declare class PreviewImageOptions {

    /**
     * 预览的图片在列表中的索引位置，从0 开始
     */
    startIndex: Number;
    /**
     * 预览的图片列表
     */
    list: Array<PreviewImageItem | Object>;
}

/**
 * 系统级接口
 * @see [说明文档] {@link https://next.informat.cn/doc/index.html#/website/system-service }
 */
interface systemService {
    /**
     * 调用本应用中的自动化
     * @param params
     * @example AutomaticParams结构
     * {
     *   automaticId: 'xxxxx';
     *   args: [];
     * }
     */
    callAutomatic(params: AutomaticParams | Object): Promise<any> | any;

    /**
     * 调用系统Toast提示
     * @param message
     */
    toast(message: string): Promise<any> | any;

    /**
     * 调用系统确认提示框
     * @param options 传入[配置项]{@link SystemConfirmOption }
     * @example
     * ```javascript
     * systemService.confirm({
     *   title: '确定要执行该操作吗？'
     * }).then(confirm => {
     *   if (!confirm) {
     *     console.log('取消了');
     *     return;
     *   }
     *   console.log('确认了');
     * });
     * ```
     */
    confirm(options: SystemConfirmOption | Object): Promise<any> | any;

    /**
     * 获取当前登录的用户
     */
    getUser(): Promise<any> | any;

    /**
     * 获取当前的应用信息
     */
    getApp(): Promise<any> | any;

    /**
     * 获取当前登录用户的Token数据
     */
    getToken(): Promise<any> | any;

    /**
     * 获取平台服务地址
     */
    getServerUrl(): Promise<string> | any;

    /**
     * 获取平台服务地址
     */
    getClientUrl(): Promise<string> | any;

    /**
     * 关闭当前弹窗
     */
    close(): Promise<any> | any;

    /**
     * 当前弹窗调用数据回包
     * @param data 可选参数
     */
    payload(data?: any): Promise<any> | any;

    /**
     * 图片预览
     * @param options 图片预览[配置项]{@link PreviewImageOptions }
     */
    previewImage(options: PreviewImageOptions | Object): Promise<any> | any;
}

/**
 * 数据表服务
 * @see [说明文档] {@link https://next.informat.cn/doc/index.html#/website/table-service }
 */
interface tableService {

    /**
     * 通过数据表的标识符获取本应用中的数据表信息
     * @param tableKey
     */
    getTableInfo(tableKey: string): Promise<any> | any;

    /**
     * 通过数据表的标识符 tableKey 查询引用中ID是 recordId 的记录数据
     * @param tableKey
     * @param recordId
     */
    queryRecordById(tableKey: string, recordId: string): Promise<any> | any;

}

/**
 * 自定义组件字段服务
 * @see [说明文档] {@link https://next.informat.cn/doc/index.html#/website/custom-field-service }
 */
interface customFieldService {
    /**
     * 获取当前表单或当前行的记录
     */
    getRecord(): Promise<any> | any;

    /**
     * 获取自定义组件字段绑定的字段信息
     */
    getField(): Promise<any> | any;

    /**
     * 获取当前字段所在的数据表信息
     */
    getTableInfo(): Promise<any> | any;

    /**
     * 设置当前表单字段值
     * @param fieldValue
     * @example
     * {
     *   field:'name',
     *   value:'xxx'
     * }
     */
    setFieldValue(fieldValue: FieldValueParam | any): Promise<any> | any;

    /**
     * 获取当前表单内字段标识符为**field**的字段是否可编辑
     * @param field 字段标识符
     */
    isFieldEditable(field: string): Promise<any> | any;

    /**
     * 获取当前表单内字段标识符为**field**的字段是否可见
     * @param field
     */
    isFieldVisible(field: string): Promise<any> | any;

    /**
     * 设置表单显示加载状态
     */
    showLoading(): Promise<any> | any;

    /**
     * 设置表单隐藏加载状态
     */
    hideLoading(): Promise<any> | any;
}

/**
 * 自定义视图服务
 * @see [说明文档] {@link https://next.informat.cn/doc/index.html#/website/custom-view-service }
 */
interface customViewService {
    /**
     * 获取当前视图数据
     */
    getTableView(): Promise<any> | any;

    /**
     * 获取当前视图的数据列表
     */
    getRecordList(): Promise<any> | any;

    /**
     * 获取当前视图的数据数量
     */
    getRecordCount(): Promise<Number> | any;

    /**
     * 修改当前视图的分页信息
     * @param {Object} pagination
     */
    changePagination(pagination: { pageIndex?: Number, pageSize?: Number }): Promise<any> | any;

    /**
     * 修改当前视图的排序信息
     * @param {Array<{
     *     // 字段标识符
     *     field: string,
     *     // 排序方式
     *     type: 'asc' | 'desc'
     * }>} orderByList  排序信息列表,非必填，不传递或者传递空数组则为重置排序
     */
    changeOrderBy(orderByList?: {
        field: string,
        type: 'asc' | 'desc'
    }[]): Promise<any> | any;

    /**
     * 获取当前视图的数据表信息
     */
    getTableInfo(): Promise<any> | any;

    /**
     * 打开记录详情页
     * @param recordId  记录ID
     */
    openRecord(recordId: string): Promise<any> | any;

    /**
     * 重新加载当前视图数据，会重置视图的分页数据
     */
    reload(): Promise<any> | any;

    /**
     * 刷新当前视图数据，不会重置视图的分页数据
     */
    refresh(): Promise<any> | any;

    /**
     * 设置当前视图选中的记录ID列表
     * @param idList  记录ID列表
     */
    setSelectedRecordIdList(idList: Array<string>): Promise<any> | any;

    /**
     * 设置当前视图的右键菜单记录
     * @param recordId  记录ID
     */
    setContextMenuRecordId(recordId: string): Promise<any> | any;
}

declare const eventService: eventService;
declare const systemService: systemService;
declare const tableService: tableService;
declare const customFieldService: customFieldService;
declare const customViewService: customViewService;
