import { request } from '/@/utils/service';
import { UserPageQuery, AddReq, DelReq, EditReq, InfoReq } from '@fast-crud/fast-crud';
import { Session } from '/@/utils/storage';

export const apiPrefix = '/api/system/job_applications/';
export function GetList(query: any) {
	return request({
		url: apiPrefix,
		method: 'get',
		params: {...query ,pageSize:query.limit,tenant_id:Session.get('tenant_id')},
	});
}
export function GetObj(id: InfoReq) {
	return request({
		url: apiPrefix + id,
		method: 'get',
	});
}

export function AddObj(obj: AddReq) {
	return request({
		url: apiPrefix,
		method: 'post',
		data: obj,
	});
}

export function UpdateObj(obj: EditReq) {
	return request({
		url: apiPrefix + obj.id + '/',
		method: 'put',
		data: obj,
	});
}

export function DelObj(id: DelReq) {
	return request({
		url:`/api/system/job_applications/${id}/?tenant_id=${Session.get('tenant_id')}`,
		method: 'delete',
		data: { id },
	});
}
export function GetPermission() {
    return request({
        url: apiPrefix,
        method: 'get',
    });
}

export function BulkUpdateStatus(data: {
	application_ids: number[];
	new_status: number;
	note?: string;
	tenant_id: string;
}) {
	return request({
		url: '/api/system/job_applications/bulk_update_status/',
		method: 'post',
		data
	});
}

export function updateBatchStatus(data: {
	application_ids: number[];
	new_status: number;
	note?: string;
	tenant_id: string;
}) {
	return request({
		url: '/api/system/job/batch_update_application_status/',
		method: 'post',
		data
	});
}

/* export function updateBatchTags(data) {
	return request({
		url: '/job-application/batch-update-tags',
		method: 'post',
		data
	});
} */

export function getApplicationStatusSummary() {
	return request({
		url: `/api/system/job/application_status_summary/?tenant_id=${Session.get('tenant_id')}`,
		method: 'get',
	});
}


/* 候选人改到人才库 */
export function candidateToTalentPool(data:any) {
	return request({
		url: '/api/system/talent_pool/import-from-application/',
		method: 'post',
		data
	});
}

/* 下载导入模板 */
export function downloadImportTemplate() {
	return request({
		url: '/api/system/sms_notifications/download_template/',
		method: 'get',
	});
}

/* 批量删除 */
export function bulkDelete(data:any) {
	return request({
		url: '/api/system/sms_notifications/bulk_delete/',
		method: 'post',
		data
	});
}

/* 使用PUT方法处理职位申请操作 */
export function updateApplicationStatus(data: {
	id: number;
	status: number;
	action: string;
	note?: string;
}) {
	return request({
		url: '/api/job/application/list',
		method: 'put',
		data
	});
}

/* 获取职位申请详情 */
export function getApplicationDetail(data: {
	id: number;
	action: string;
}) {
	return request({
		url: '/api/job/application/list',
		method: 'put',
		data
	});
}

/* 批量更新职位申请状态 */
export function batchUpdateApplicationStatus(data: {
	ids: number[];
	status: number;
	action: string;
	note?: string;
}) {
	return request({
		url: '/api/job/application/list',
		method: 'put',
		data: {
			...data,
			batch: true
		}
	});
}

export function updateSmsNotification(id: number, data: { name: string; phone: string; id_card: string; description: string; }) {
	return request({
		url: `/api/system/sms_notifications/${id}/`,
		method: 'put',
		data
	});
}
