import { getReq, postReq, putReq } from '@/utils/requestUtil';

export function getXunJianDownloadUrlApi(idList) {
    return getReq('/ranger/inspection/api/v1/jobs/export', { jobIdList: idList.join(',') });
}

export function addXunJianTaskApi(data) {
    return postReq('/ranger/inspection/api/v1/jobs/temporary', data);
}

export function getRegionInfoApi(id) {
    return getReq(`/ranger/inspection/api/v1/region/${id}`);
}

export function addRegionApi(data) {
    return postReq('/ranger/inspection/api/v1/region', data);
}

export function editRegionApi(data) {
    return putReq(`ranger/inspection/api/v1/region`, data);
}

export function getPlaceInfoApi(id) {
    return getReq(`/ranger/inspection/api/v1/place/${id}`);
}

export function addPlaceApi(data) {
    return postReq('/ranger/inspection/api/v1/place', data);
}

export function editPlaceApi(data) {
    return putReq('/ranger/inspection/api/v1/place', data);
}

export function getExemptionsListApi(data) {
    return getReq(`/ranger/inspection/api/v1/exemptions/valid`, data);
}

export function addUnitApi(data) {
    return postReq('/ranger/inspection/api/v1/units', data);
}

export function editUnitApi(data) {
    return putReq('/ranger/inspection/api/v1/units', data);
}

export function getUnitInfoApi(id) {
    return getReq(`/ranger/inspection/api/v1/units/${id}`);
}

export function getItemsInfoApi(id) {
    return getReq(`/ranger/inspection/api/v1/items/${id}`);
}

export function addItemsApi(data) {
    return postReq('/ranger/inspection/api/v1/items', data);
}

export function editItemsApi(data) {
    return putReq('/ranger/inspection/api/v1/items', data);
}
export function addExemptionApi(data) {
    return postReq('/ranger/inspection/api/v1/exemptions', data);
}

export function getExemptionApi(id) {
    return getReq(`ranger/inspection/api/v1/exemptions/${id}`);
}

export function updateExemptionApi(data) {
    return putReq(`/ranger/inspection/api/v1/exemptions`, data);
}

export function addMajorApi(data) {
    return postReq(`/ranger/inspection/api/v1/specialities`, data);
}
export function updateMajorApi(data) {
    return putReq('/ranger/inspection/api/v1/specialities', data);
}

export function getMajorInfoApi(id) {
    return getReq(`/ranger/inspection/api/v1/specialities/${id}`);
}

export function getOrganizationUserApi(id) {
    return getReq(`/api/v1/users/organizations/${id}`);
}

export function addSpecialitiesStaffsApi(data) {
    return postReq(`/ranger/inspection/api/v1/specialities/staffs`, data);
}

export function getRouteInfoApi(id) {
    return getReq(`/ranger/inspection/api/v1/routes/${id}`);
}
export function addRouteInfoApi(data) {
    return postReq(`/ranger/inspection/api/v1/routes`, data);
}
export function updateRouteInfoApi(data) {
    return putReq(`/ranger/inspection/api/v1/routes`, data);
}

export function getTemplateApi() {
    return getReq(
        `/ranger/inspection/api/v1/routes/downLoadRouteImportTemplate`,
        {},
        { responseType: 'blob' },
    );
}

export function exportRouteData(data) {
    return getReq(`/ranger/inspection/api/v1/routes/exportRouteData`, data, { responseType: 'blob' });
}

export function updateRouteStateApi(data) {
    return putReq(`/ranger/inspection/api/v1/routes/routeState`, data);
}

/**
 * 上传文件
 */
export function uploadFileRouteApi(data = {}, file) {
    const formData = new FormData();
    Object.keys(data).forEach((key) => {
        formData.append(key, data[key]);
    });
    formData.append('file', file);
    return postReq('/ranger/inspection/api/v1/routes/upload', formData);
}
export function getRouteSchedulesListApi(data) {
    return getReq(`/ranger/inspection/api/v1/route/schedules`, data);
}
export function updateRouteSchedulesStateApi({ id, state }) {
    return putReq(`/ranger/inspection/api/v1/route/schedules/${id}?shiftState=${state}`);
}
export function addRouteSchedulesApi(data) {
    return postReq(`/ranger/inspection/api/v1/route/schedules`, data);
}
export function updateRouteSchedulesApi(data) {
    return postReq(`/ranger/inspection/api/v1/route/schedules`, data);
}
export function getRouteAssemblesApi(data) {
    return getReq(`/ranger/inspection/api/v1/route/assembles`, data);
}
export function getRouteAssemblesListApi(data) {
    return getReq(`/ranger/inspection/api/v1/route/assembles/assembleList`, data);
}
