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 getScienceMethod(id: string) {
  return Get(`/psarticle/getPsarticleDetailById`, {
    params: { popularScienceArticleId: id },
    transform({ data }: AnyObject) {
      const { popularScienceArticleId: id, ..._data } = data;
      return { id, ..._data };
    }
  })
}