import request from '@/utils/request';
import { AxiosPromise } from 'axios';

// 查询公司接口
export function getCompanyList() {
    return request({
        url: '/lingcun/subCompany/list',
        method: 'get'
    })
}

// 根据公司id查询部门接口
export function getDepartmentList(subCompanyId: string) {
    return request({
        url: '/sys/dept/getListBySub',
        method: 'post',
        data: { subCompanyId }
    })
}

// 根据部门id查询员工接口
export function getPersonList(deptId: string) {
    return request({
        url: '/sys/user/listByDeptId',
        method: 'post',
        data: { deptId }
    })
}

// 评论通用接口
interface addTypes {
    type: string;
    content: string;
    recordId?: string
}

export interface listTypes {
    id: string;
    staffPhoto: string;
    staffName: string;
    createTime: string;
    content: string;
    recordId: string;
}

/**
 * 添加
 * @param query
 * @returns {*}
 */

export const addComment = (query: addTypes) => {
    return request({
        url: '/record-comment/add',
        method: 'post',
        data: query
    });
};

/**
 * 查询
 * @param query
 * @returns {*}
 */

export const listComment = (query): AxiosPromise<{ records: listTypes[] }> => {
    return request({
        url: '/record-comment/list',
        method: 'post',
        data: query
    });
};

/**
 * 删除
 * @param id
 * @returns {*}
 */

export const deleteComment = (commentId: string) => {
    return request({
        url: '/record-comment/delete',
        method: 'post',
        data: { commentId }
    });
};

/**
 * 查询动态接口
 * @param data
 * @returns {*}
 */
export const listDynamic = (data: { recordId?: string, type: number } & PageQuery) => {
    return request({
        url: '/dynamic-log/list',
        method: 'post',
        data
    });
};

// 表格导入导出通用接口
/**
 * 获取导入模板
 * @param templateCode
 * @returns {*}
 */
export const downloadTemplate = (templateCode: string, importType?: string) => {
    return request({
        url: '/excel/download_import_template',
        method: 'post',
        data: { templateCode, importType },
        responseType: "blob",
        responseEncoding: "utf8"
    });
};

/**
 * 下载异常文件
 * @param templateCode
 * @returns {*}
 */
export const downloadFailTemplate = (tempCode: string, importType?: string) => {
    return request({
        url: '/excel/export_temp',
        method: 'post',
        data: { tempCode, importType },
        responseType: "blob",
        responseEncoding: "utf8"
    });
};

/**
 * 导入
 * @param query
 * @returns {*}
 */
export const listImport = (tempCode: string, importType?: string, resourceType?: number) => {
    return request({
        url: '/excel/save_import_data',
        method: 'post',
        data: { tempCode, importType, resourceType },
        timeout: 0
    });
};

/**
 * 导出
 * @param query
 * @returns {*}
 */
export const listExport = (query: any) => {
    return request({
        url: '/excel/export',
        method: 'post',
        data: query,
        responseType: "blob",
        responseEncoding: "utf8"
    });
};

// 消息模块接口
/**
 * 消息列表
 * @param data
 * @returns {*}
 */
export const listMessage = (data: any) => {
    return request({
        url: '/sys/inside/message/pageList',
        method: 'post',
        data
    });
};

/**
 * 获取类型以及未读数量
 * @param data
 * @returns {*}
 */
export const getMessageType = () => {
    return request({
        url: '/sys/inside/message/getNoReadCount',
        method: 'post',
        data: {}
    });
};

/**
 * 获取公告未读数量
 * @param data
 * @returns {*}
 */
export const getBulletinUnreadCount = () => {
    return request({
        url: '/bulletin/unread-count',
        method: 'get',
        params: {}
    });
};

/**
 * 更新为已读
 * @param data
 * @returns {*}
 */
export const updateRead = (ids: string[]) => {
    return request({
        url: '/sys/inside/message/read',
        method: 'post',
        data: {
            messageLogIds: ids
        }
    });
}

/**
 * 全部已读
 * @returns {*}
 */
export const updateReadAll = () => {
    return request({
        url: '/sys/inside/message/readAll',
        method: 'post',
        data: {}
    });
}

/**
 * 清空已读
 * @returns {*}
 */
export const clearRead = () => {
    return request({
        url: '/sys/inside/message/cleanAll',
        method: 'post',
        data: {
            isRead: 1
        }
    });
}

/**
 * 查询附件接口
 * @param resourceType
 * @returns {*}
 */
export interface resourceQuery {
    resourceType?: string;
    resourceTypeId?: string;
    customerId?: string | number;
}
export interface resourceVO {
    id: string | number;
    createTime: string;
    resourceName: string;
    resourceSize: string;
    createBy: string;
    resourceExt: string;
    resourceUrl: string;
}
export const listResource = (params: resourceQuery): AxiosPromise<{ records: resourceVO[] }> => {
    return request({
        url: '/sys-resource/list',
        method: 'get',
        params
    });
};

/**
 * 附件绑定资源接口
 * @param ids
 * @returns {*}
 */
export const bindResource = (data: { idList: number[], remark: string } & resourceQuery) => {
    return request({
        url: '/sys-resource/add-resource',
        method: 'post',
        data
    });
};

/**
 * 删除附件接口
 * @param ids
 * @returns {*}
 */
export const delResource = (id: string | number) => {
    return request({
        url: '/sys-resource/delete-by-id',
        method: 'delete',
        data: {
            id
        }
    });
};

/**
 * 批量删除附件接口
 * @param ids
 * @returns {*}
 */
export const batchDelResource = (ids: (string | number)[]) => {
    return request({
        url: '/sys-resource/delete',
        method: 'delete',
        data: {
            ids
        }
    });
};

// 操作日志接口
export interface OperationLogQuery {
    resourceType?: string;
    resourceTypeId?: string;
    beginTime?: string;
    endTime?: string;
}
export interface OperationLogVO {
    operationTime: string;
    ownerByName: string;
    operationType: number;
    fieldName: string;
    oldValue: string;
    newValue: string;
    dataType: string;
}
export const listOperationLog = (data: OperationLogQuery & PageQuery): AxiosPromise<{ records: OperationLogVO[] }> => {
    return request({
        url: '/operation-log/list',
        method: 'post',
        data
    });
}
