import { Get, Post } from "../../lib/request/method";

export function getDietListMethod(
  page: number,
  size: number,
  query?: { keyword?: string; classify: "tonic" | "tea" }
) {
  return Post(
    `/dietRecipe/pageDietRecipe`,
    { page, limit: size, classify: query?.classify, keyWord: query?.keyword },
    {
      transform({ data }: AnyObject) {
        return {
          total: data.total,
          page: data?.current ?? page,
          size: data?.size ?? size,
          data: data.records,
        };
      },
    }
  );
}

export function getDietMethod(id: string) {
  return Post(
    `/dietRecipe/dietRecipeDetail`,
    { id },
    {
      transform({ data }: AnyObject) {
        return data;
      },
    }
  );
}

export function getScienceListMethod(
  page: number,
  size: number,
  query?: { keyword?: string }
) {
  return Post(
    `/psarticle/pagePsarticle?pageNum=${page}&pageSize=${size}&keyword=${query?.keyword}`,
    void 0,
    {
      transform({ data }: AnyObject) {
        return {
          total: data.total,
          page: data?.current ?? page,
          size: data?.size ?? size,
          data: data.data.map(
            (item: AnyObject) => (
              (item.id = item.popularScienceArticleId), item
            )
          ),
        };
      },
    }
  );
}
// 宣教通知
export function getScienceNoticeListMethod(
  page: number,
  size: number,
  query?: { keyword?: string }
) {
  return Post(
    `/psarticle/pagePsaNotice?pageNum=${page}&pageSize=${size}&keyword=${query?.keyword}`,
    void 0,
    {
      transform({ data }: AnyObject) {
        return {
          total: data.total,
          page: data?.current ?? page,
          size: data?.size ?? size,
          data: data.data.map(
            (item: AnyObject) => (
              (item.id = item.popularScienceArticleId), item
            )
          ),
        };
      },
    }
  );
}

export function getScienceMethod(id: string) {
  return Get(`/psarticle/getPsarticleDetailById`, {
    params: { popularScienceArticleId: id },
    transform({ data }: AnyObject) {
      const { popularScienceArticleId: id, ..._data } = data;
      return { id, ..._data };
    },
  });
}
// 获取所有地址列表
export function getAddressListMethod(id: string, keyWord: string) {
  return Post(
    `/patientCrManage/patAddress/all`,
    {
      id,
      keyWord,
    },
    {
      transform({ data }: AnyObject) {
        return data;
      },
    }
  );
}
//新增患者地址
export function addAddressMethod(data: AnyObject) {
  return Post(`/patientCrManage/patAddress/save`, data, {
    transform({ data }: AnyObject) {
      return data;
    },
  });
}
// 删除患者地址
export function deleteAddressMethod(id: string) {
  console.log(id, "删除地址的id");
  return Post(`/patientCrManage/patAddress/delete/${id}`, {
    transform({ data }: AnyObject) {
      return data;
    },
  });
}
// 根据患者id地址详情
export function getAddressDetailByPatientIdMethod(id: string) {
  return Post(`/patientCrManage/patAddress/detail/${id}`, {
    transform({ data }: AnyObject) {
      return data;
    },
  });
}
// 更新地址
export function updateAddressMethod(data: AnyObject) {
  return Post(`/patientCrManage/patAddress/update`, data, {
    transform({ data }: AnyObject) {
      return data;
    },
  });
}
// 获取订单详情
export function getOrderDetailMethod(id: string) {
  return Post(`/patientCrManage/getPcrDetailById/${id}`, {
    transform({ data }: AnyObject) {
      return data;
    },
  });
}
// 订单支付接口
export function orderPayMethod(id: string) {  
  return Post(`/patientCrManage/payPcr/${id}`, {
    transform({ data }: AnyObject) {
      return data;
    },
  });
}
//支付地址修改
export function orderPayAddressMethod(id: string, data: AnyObject) {
  return Post(`/patientCrManage/payPcr/addressEdit/${id}`, data, {
    transform({ data }: AnyObject) {
      return data;
    },
  });
}
// 订单取消
export function orderCancelMethod(id: string) {
  return Post(`/patientCrManage/cancelPcr/${id}`, {
    transform({ data }: AnyObject) {
      return data;
    },
  });
}
// 订单列表
export function orderListMethod(patientId: number, orderStatus: string) {
  return Post(`/patientCrManage/pagePcrOrders`, { patientId, status:'0', orderStatus }, {
    transform({ data }: AnyObject) {
      return data;
    },
  });
}
// 确认收货
export function orderConfirmMethod(id: string) {
  return Post(`/patientCrManage/confirmPcr/${id}`, {
    transform({ data }: AnyObject) {
      return data;
    },
  });
}
//新的确认收货接口
export function orderConfirmReceiptMethod(patientConditioningRecordId: string,integers:number[]) {
  return Post(`/patientCrManage/confirmReceipt/${patientConditioningRecordId}`, integers,{
    transform({ data }: AnyObject) {
      return data;
    },
  });
}
// 获取足迹列表
export function getFootPrintListMethod() {
  return Post(`/patientInfoManage/getMyFootprint`, {
    transform({ data }: AnyObject) {
      return data;
    },
  });
}
