import { req } from '@/common/js/index.js';
import { unwrapClinicRes } from '@/api/clinicAdmin.js';

const PREFIX = '/newApi/clinic-salesperson-self';
const AUTH_PREFIX = '/newApi/clinic-salesperson-auth';

function clinicSalespersonRequest(options) {
	return req.request({
		...options,
		header: {
			...(options.header || {}),
			_clinicSalesperson: '1',
		},
	}).then((res) => {
		const data = unwrapClinicRes(res);
		const ok = res && (res.code === 0 || (res.errcode != null && Number(res.errcode) !== -1));
		return { res, data, ok };
	});
}

export function getClinicSalespersonMyInfo() {
	return clinicSalespersonRequest({ url: `${AUTH_PREFIX}/my-info`, method: 'GET' });
}

export function getClinicSalespersonCommissionList(params) {
	return clinicSalespersonRequest({ url: `${PREFIX}/commission-list`, method: 'GET', data: params });
}

export function getClinicSalespersonSettlementList(params) {
	return clinicSalespersonRequest({ url: `${PREFIX}/settlement-list`, method: 'GET', data: params });
}

export function getClinicSalespersonSettlementDetail(id) {
	return clinicSalespersonRequest({ url: `${PREFIX}/settlement-detail`, method: 'GET', data: { id } });
}

export function getClinicSalespersonUserBindList(params) {
	return clinicSalespersonRequest({ url: `${PREFIX}/user-bind-list`, method: 'GET', data: params });
}

export function getClinicSalespersonSeePriceConfig() {
	return clinicSalespersonRequest({ url: `${PREFIX}/see-price-config`, method: 'GET' });
}

export function getClinicSalespersonChineseDrugList(params) {
	return clinicSalespersonRequest({ url: `${PREFIX}/chinese-drug-list`, method: 'GET', data: params });
}

export function getClinicSalespersonDiseaseList(params) {
	return clinicSalespersonRequest({ url: `${PREFIX}/disease-list`, method: 'GET', data: params });
}

export function getClinicSalespersonProcessRuleList(params) {
	return clinicSalespersonRequest({ url: `${PREFIX}/process-rule-list`, method: 'GET', data: params });
}

export function getClinicSalespersonChineseMedicineQuickGrams() {
	return clinicSalespersonRequest({ url: `${PREFIX}/chinese-medicine-quick-grams`, method: 'GET' });
}

export function createClinicSalespersonTransferPrescription(data) {
	return clinicSalespersonRequest({ url: `${PREFIX}/transfer-prescription-create`, method: 'POST', data });
}

export function getClinicSalespersonTransferPrescriptionList(params) {
	return clinicSalespersonRequest({ url: `${PREFIX}/transfer-prescription-list`, method: 'GET', data: params });
}

export function getClinicSalespersonTransferPrescriptionDetail(id) {
	return clinicSalespersonRequest({ url: `${PREFIX}/transfer-prescription-detail`, method: 'GET', data: { id } });
}

/** 我邀请的下级推广员列表 */
export function getClinicSalespersonInvitedList(params) {
	return clinicSalespersonRequest({ url: `${PREFIX}/invited-salesperson-list`, method: 'GET', data: params });
}
