import {request} from "@/api/request";
import {Category} from "@/api/public";

export interface AdwareParams {
  key: string
  value: string

  [key: string]: string
}

export interface AdwareLinkType {
  id: number
  api_name: string
  path: string
  param: string
}

export interface AdwareType {
  image_path: string
  advert_link: AdwareLinkType
  scope_id: number | string
  id: number
  name: string
  status: 0 | 1 // 禁用
  sort: number
  image_url: string
  image_link: string
  start_time: number
  end_time?: number
}

export interface HomeData {
  adverts: AdwareType[]
  skill: Kill[]
  health: Health[]
  brand: {
    list: Brand[]
  }
  illness: {
    list: Illness[]
  }
}

interface Course {
  articles:any[]
  audit_mode:boolean
  course:{ data: Curriculum[], total: number }
}

export const HomeApi = {
  advert(only_flag: string) {
    return request<AdwareType[]>("/home/v1/advert/unique?only_flag=" + only_flag, "GET")
  },
  course(page: number, page_size: number) {
    return request<Course>('/home/v1/course/course', "GET", {page, page_size})
  },
  /** 健康管理 */
  healthTop(count: number) {
    return request<Health[]>('/home/v1/health/top', "GET", {count})
  },
  health(page: number, page_size: number) {
    return request<{ data: Health[], total: number }>('/home/v1/health/index', "GET", {page, page_size})
  },
  /** 增加播放量 */
  healthSetPlay(id) {
    return request(`/home/v1/health/set_play/${id}`, "PUT")
  },
  /** 品牌 */
  brand(page: number, page_size: number) {
    return request<{ list: Brand[], total: number }>('/home/v1/brand/list', "GET", {page, page_size})
  },
  /** 技能 */
  skillTop(count: number) {
    return request<Kill[]>('/home/v1/skill/top', "GET", {count})
  },
  skillCategory() {
    return request<Category[]>('/home/v1/skill/category', "GET")
  },
  skillList(categoryId: number, page: number, page_size: number) {
    return request<{ data: Kill[], total: number }>('/home/v1/skill/index', "GET", {categoryId, page, page_size})
  },
  skillSetPlay(id: number) {
    return request(`/home/v1/skill/set_play/${id}`, "PUT")
  },
  /** 疾病知识 */
  illness(page: number, page_size: number) {
    return request<{ list: Illness[], total: number }>('/home/v1/article/illness_list', "GET", {page, page_size})
  },
  category(type: number) {
    return request<Category[]>('/home/v1/category/index/info?type=' + type, "GET")
  },
  home() {
    return request<HomeData>('/home/v1/home/home_page', "GET", {count: 3})
  }
}
