import { requestClient } from '#/api/request';

const prefix = 'store-input/';

/**
 * 创建录入
 * @param data
 */
export async function createStoreInput(data: Record<string, any>) {
  return requestClient.post<any>(`${prefix}create`, data);
}

/**
 * 获取录入列表
 * @param data
 */
export async function getStoreInputList(data: any) {
  return requestClient.get<any>(`${prefix}list`, { params: data });
}

/**
 * 获取录入详情
 * @param id
 */
export async function getStoreInputDetail(id: number) {
  return requestClient.get<any>(`${prefix}detail`, { params: { id } });
}

/**
 * 更新录入
 * @param data
 */
export async function updateStoreInput(data: Record<string, any>) {
  return requestClient.post<any>(`${prefix}update`, data);
}

/**
 * 审核录入
 * @param data
 */
export async function getPromoterOptions() {
  return requestClient.get<{
    id: number;
    nick_name: string;
    avatar: string;
    code: string;
    phone: string;
    role_id: number;
    role_name: string;
  }[]>(`${prefix}promoter-options`);
}

export type PromoterStoreListItem = {
  store_id: number;
  name: string;
  type: number;
  type_label: string;
  input_at: number;
  total_amount: string;
  month_amount: string;
};

export async function getPromoterDetailApi(params: { id?: number; code?: string }) {
  return requestClient.get<{
    id: number;
    nick_name: string;
    avatar: string;
    code: string;
    phone: string;
    role_name: string;
    clinic_store_count: number;
    pharmacy_store_count: number;
    store_total_count: number;
    pending_clinic_count: number;
    pending_pharmacy_count: number;
    store_list: PromoterStoreListItem[];
    total_valid_amount: string;
    month_valid_amount: string;
  }>(`${prefix}promoter-detail`, { params });
}

export async function auditStoreInput(data: {
  id: number;
  status: number; // 1=审核通过，2=审核拒绝
  audit_remark?: string;
  erp_id?: number | string;
  mes_id?: number | string;
  /** 门店审核通过时一并审核的医生预填 ID */
  doctor_input_ids?: number[];
}) {
  return requestClient.post<any>(`${prefix}audit`, data);
}
