import request from "@/utils/request";

// 查询学习卡列表
export function listCards(query) {
  return request({
    url: "/dz/cards/list",
    method: "get",
    params: query,
  });
}

// 查询学习卡详细
export function getCards(cardId) {
  return request({
    url: "/dz/cards/" + cardId,
    method: "get",
  });
}

// 新增学习卡
export function addCards(data) {
  return request({
    url: "/dz/cards",
    method: "post",
    data: data,
  });
}

// 修改学习卡
export function updateCards(data) {
  return request({
    url: "/dz/cards",
    method: "put",
    data: data,
  });
}

// 删除学习卡
export function delCards(cardIds) {
  // 如果是数组，转换为逗号分隔的字符串
  const ids = Array.isArray(cardIds) ? cardIds.join(",") : cardIds;
  return request({
    url: "/dz/cards/" + ids,
    method: "delete",
  });
}

// 制卡
export function issueCard(institutionId, type, count) {
  return request({
    url: "/dz/cards/issueCard",
    method: "post",
    params: {
      institutionId,
      type,
      count,
    },
  });
}

// 分配卡
export function assignCard(
  cardType,
  agentId,
  begin,
  end,
  location,
  examType,
  schoolId
) {
  return request({
    url: "/dz/cards/assignCard",
    method: "post",
    params: {
      cardType,
      agentId,
      begin,
      end,
      location,
      examType,
      schoolId,
    },
  });
}

// 获取考生类型列表
export function getExamTypes(location) {
  return request({
    url: "/front/user/examTypes",
    method: "get",
    params: {
      location,
    },
  });
}

// 获取代理商列表
export function getAgentList(query) {
  return request({
    url: "/dz/agent/list",
    method: "get",
    params: query,
  });
}

// 缴费
export function payCard(cardIds) {
  return request({
    url: "/dz/cards/changeCard",
    method: "post",
    params: {
      action: "Pay",
      cardIds: Array.isArray(cardIds) ? cardIds.join(",") : cardIds,
    },
  });
}

// 关卡
export function closeCard(cardIds) {
  return request({
    url: "/dz/cards/changeCard",
    method: "post",
    params: {
      action: "Close",
      cardIds: Array.isArray(cardIds) ? cardIds.join(",") : cardIds,
    },
  });
}

// 重开
export function reopenCard(cardIds) {
  return request({
    url: "/dz/cards/changeCard",
    method: "post",
    params: {
      action: "ReOpen",
      cardIds: Array.isArray(cardIds) ? cardIds.join(",") : cardIds,
    },
  });
}

// 退费
export function refundCard(cardIds) {
  return request({
    url: "/dz/cards/changeCard",
    method: "post",
    params: {
      action: "Refund",
      cardIds: Array.isArray(cardIds) ? cardIds.join(",") : cardIds,
    },
  });
}

// 获取学校列表
export function getSchoolList(query) {
  return request({
    url: "/dz/school/getSchoolList",
    method: "get",
    params: query,
  });
}

// 获取校区列表
export function getCampusSchoolList(query) {
  return request({
    url: "/dz/school/getCampusSchoolList",
    method: "get",
    params: query,
  });
}

// 关联校区
export function associateCampus(beginCardNo, endCardNo, campusId) {
  return request({
    url: "/dz/cards/changeCampus",
    method: "post",
    params: {
      campusId,
      begin: beginCardNo,
      end: endCardNo,
    },
  });
}

// 申请开卡
export function requestOpenCard(agentId, province, schoolId, beginCardNo, endCardNo) {
  return request({
    url: "/dz/cards/openCard",
    method: "post",
    params: {
      agentId: agentId,
      location: province,
      schoolId,
      begin: beginCardNo,
      end: endCardNo,
    },
  });
}
