import { SmartSaveDataType } from "@/types";
import http from "@/utils/http";
import { AppDispatch } from "..";

/**
 * 配置-获取
 */
export const smartGetConfigAPI = () => {
  return http.get("cms/guide/getConfig");
};

/**
 * 配置-修改
 */
export const smartSetConfigAPI = (data: { content: string }) => {
  return http.post("cms/guide/setConfig", data);
};

/**
 * 播报表格-是否显示
 */
export const smartDisplayAPI = (id: number, display: number) => {
  return http.get(`cms/guide/display/${id}/${display}`);
};

/**
 * 获取表格列表
 */
export const smartGetListAPI = (type: "hot" | "play") => {
  return async (dispatch: AppDispatch) => {
    const res = await http.get(`cms/guide/list/${type}`);
    if (res.code === 0) {
      dispatch({
        type: type === "hot" ? "smart/getHotList" : "smart/getAutoList",
        payload: res.data,
      });
    }
  };
};

/**
 * 内容-排序
 */
export const smartSortAPI = (id1: number, id2: number) => {
  return http.get(`cms/guide/sort/${id1}/${id2}`);
};

/**
 * 内容-删除
 */
export const smartRemoveAPI = (id: number) => {
  return http.get(`cms/guide/remove/${id}`);
};

/**
 * 内容-新增、编辑
 */
export const smartSaveAPI = (data: SmartSaveDataType) => {
  return http.post("cms/guide/save", data);
};

/**
 * 内容-删除
 */
export const getSmartDetailAPI = (id: number) => {
  return http.get(`cms/guide/detail/${id}`);
};
