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

export const apiPrefix = '/api/system/job/create';

export function GetPermission() {
	return request({
		url: apiPrefix + 'field_permission/',
		method: 'get',
	});
}

export function GetList(query: PageQuery) {
	return request({
		url: '/api/system/job/list',
		method: 'get',
		params: {...query,tenant_id:Session.get('tenant_id')},/* :.tenant_id ||  */
	});
}
export function GetObj(id: InfoReq) {
	return request({
		url: "/api/system/job/detail?id=" + id+"&tenant_id="+Session.get('tenant_id'),
		method: 'get',
	});
}

export function AddObj(obj: AddReq) {
	return request({
		url: "/api/system/job/create",
		method: 'post',
		data: {...obj,tenant_id: Session.get('tenant_id')},/* Session.get('tenant_id').tenant_id || */
	});
}

export function UpdateObj(obj: EditReq) {
	return request({
		url: "/api/system/job/update",/* + obj.id+'/' */
		method: 'post',
		data: {...obj,tenant_id: Session.get('tenant_id')},
	});
}

export function DelObj(id: DelReq) {
	return request({
		url: '/api/system/job/delete',/* + id + '/' */
		method: 'delete',
		data: { id,tenant_id: Session.get('tenant_id') },
	});
}

export function BatchUpdateTags(data: any) {
	return request({
		url: '/api/system/competency/batch_bind',
		method: 'post',
		data
	});
}

export function GetCompetencyList(query:any) {
	console.log(Session.get('user'));
	return request({
		url: '/api/system/competency/list',
		method: 'get',
		params: {...query,tenant_id:Session.get('tenant_id')},
	});
}

/* 发布职位 */
export function PublishPosition(data:any) {
	return request({
		url: 'api/system/job/update_status',
		method: 'post',
		data: JSON.stringify(data),
		headers: {
			'Content-Type': 'application/json'
		}
	});
}

/* 批量修改状态 */
export function batch_publish(data:any) {
	return request({
		url: '/api/system/job/batch_publish',
		method: 'post',
		data: JSON.stringify(data),
		headers: {
			'Content-Type': 'application/json'
		}
	});
}

/* AI生成职位描述 */
export function GeneratePositionDescription(data:any) {
	return request({
		url: '/api/ai/generate_job_description',
		method: 'post',
		data: JSON.stringify(data),
		headers: {
			'Content-Type': 'application/json',
			'Authorization': 'JWT ' +Session.get('token')
		}
	});
}

/* 检测是否有题目可以发布 */
export function CheckQuestionVideosStatus(data:any) {
	return request({
		url: 'api/system/job/question_videos_status',
		method: 'get',
		params: data,
	});
}

