// 伴宠师-伴宠师考核
import request from '@/utils/request'

// 伴宠师工作台-查询专业执照列表
export const getLicenseList = () => {
	return request({
		url: '/applet/examination/licenseList',
		method: "get"
	}).then(res => {
		return res.data
	})
}

export const getServiceList = (params) => {
	return request({
		url: '/applet/config/serviceList',
		method: "get",
		params
	}).then(res => {
		return res.data?.map?.(item => {
			const {
				id,
				title,
				video
			} = item

			return {
				id,
				title,
				video
			}
		}) || []
	})
}

export const getTrainList = (params) => {
	return request({
		url: '/applet/config/trainList',
		method: "get",
		params
	}).then(res => {
		return res.data?.map?.(item => {
			const {
				id,
				title,
				content
			} = item

			return {
				id,
				title,
				content
			}
		}) || []
	})
}

// 伴宠师工作台-题目列表数据查询
export const getQuestionList = (params) => {
	return request({
		url: '/applet/examination/questionList',
		method: "get",
		params
	}).then(res => {
		return res.data
	})
}

// 伴宠师工作台-根据题目id查询题目答案
export const getQuestionOptions = (params) => {
	return request({
		url: '/applet/examination/insertUser',
		method: "get",
		params
	}).then(res => {
		return res.data
	})
}

// 伴宠师工作台-添加用户基本考核答案
export const addBaseAnswer = (data) => {
	return request({
		url: '/applet/examination/addBaseAnswerV2',
		headers: {
			isToken: true
		},
		method: 'post',
		data
	})
}

// 伴宠师工作台-根据题目id查询基本考核答案
export const answeBaseByQuestionId = (params) => {
	return request({
		url: '/applet/examination/answeBaseByQuestionId',
		headers: {
			isToken: true
		},
		method: "get",
		params
	}).then(res => {
		return res.data?.pop() || {}
	})
}

// 伴宠师工作台-添加用户培训考核答案
export const addTrainAnswer = (data) => {
	return request({
		url: '/applet/examination/addTrainAnswer',
		headers: {
			isToken: true
		},
		method: 'post',
		data
	})
}

// 伴宠师工作台-根据题目id查询培训考核答案
export const answeTrainByQuestionId = (params) => {
	return request({
		url: '/applet/examination/answeTrainByQuestionId',
		headers: {
			isToken: true
		},
		method: "get",
		params
	}).then(res => {
		return res.data?.pop() || {}
	})
}


// 伴宠师工作台-查询用户基本考核是否完成
export const answeBaseIsFinish = (params) => {
	return request({
		url: '/applet/examination/answeBaseIsFinishV2',
		headers: {
			isToken: true
		},
		method: "get",
		params
	}).then(res => {
		return res.data == 1
	})
}


// 伴宠师工作台-查询用户培训考核是否完成
export const answeTrainIsFinish = (params) => {
	return request({
		url: '/applet/examination/answeTrainIsFinishV2',
		headers: {
			isToken: true
		},
		method: "get",
		params
	}).then(res => {
		return res.data == 1
	})
}


// 伴宠师工作台-成为伴宠师
export const appletUsersTeacher = (params) => {
	return request({
		url: '/applet/examination/appletUsersTeacher',
		headers: {
			isToken: true
		},
		method: "get",
		params
	})
}


// 伴宠师工作台-重新考试
export const retakeExam = (params) => {
	return request({
		url: '/applet/examination/retakeExam',
		headers: {
			isToken: true
		},
		method: "get",
		params
	})
}



// 伴宠师工作台-查询考试结果对象
export const getAnswerBuildData = (userId) => {
	return request({
		url: '/applet/examination/getAnswerBuildData',
		headers: {
			isToken: true
		},
		method: 'get',
		params : {
			userId
		}
	}).then(res => res.data)
}