import request from "@/config/axios";

// 钉钉扫码登录
export async function socialLogin(type: string, code: string, state: string) {
  return await request.post({
    url: "/admin-api/system/auth/social-login",
    data: {
      type,
      code,
      state,
    },
  });
}

// 登出
export const loginOut = () => {
  return request.post({ url: "/admin-api/system/auth/logout" });
};

// 获取用户权限信息
export const getUserInfo = () => {
  return request.get({ url: "/admin-api/system/auth/get-permission-info" });
};

// 密码登陆

type UserLoginVO = {
  username: string;
  password: string;
  captchaVerification: string;
  socialType?: string;
  socialCode?: string;
  socialState?: string;
};
export const login = (data: UserLoginVO) => {
  return request.post({
    url: "/admin-api/system/auth/login",
    data,
  });
};

// SSO登录
export const ssoLogin = (data: any) => {
  return request.post({
    url: "/admin-api/system/auth/oaSsoToken",
    headers: { "Content-Type": "application/json" },
    data,
  });
};

// SRM SSO登录
export const srmLogin = (data: any) => {
  return request.post({
    url: "/admin-api/system/auth/srm-sso-token",
    headers: { "Content-Type": "application/json" },
    data,
  });
};

// EHR 登录
export const ehrLogin = (data: any) => {
  return request.post({
    url: "/admin-api/system/auth/ehrLogin",
    headers: { "Content-Type": "application/json" },
    data,
  });
};

export const zentaoSsoLogin = (data: any) => {
  return request.post({
    url: "/admin-api/system/auth/zentaoSsoToken",
    headers: { "Content-Type": "application/json" },
    data,
  });
};

export const getUnreadNotifyMessageCount = async () => {
  return await request.get({
    url: "/admin-api/system/notify-message/get-unread-count",
  });
};

// 经营驾驶舱sso
export const getMCSsoToken = async () => {
  // https://portal.deepoil.cc/admin-api/rq/iot-fine-report/createSsoToken
  return await request.get({
    url: "/admin-api/rq/iot-fine-report/createSsoToken",
  });
};

// 分组接口
export const getGroups = async () => {
  return await request.get({
    url: "/admin-api/portal/flow-group/page",
  });
};

// 根据id获取分组详情
export const getGroupById = async (id: string) => {
  return await request.get({
    url: "/admin-api/portal/flow/get?groupId=" + id,
  });
};

// 获取所有的flow
export const getFlows = async (params) => {
  return await request.get({
    url: "/admin-api/portal/flow-group/all",
    params,
  });
};

// oa待办任务
export const getOATasks = async (params) => {
  return await request.get({
    url:
      "/admin-api/portal/todo/oa?workcode=" +
      params.id +
      "&pageNo=" +
      params.pageNum +
      "&pageSize=" +
      params.pageSize,
  });
};

// crm待办任务
export const getCRMTasks = async (params) => {
  return await request.get({
    url:
      "/admin-api/portal/todo/crm?workcode=" +
      params.id +
      "&type=" +
      params.type +
      "&pageNo=" +
      params.pageNum +
      "&pageSize=" +
      params.pageSize,
  });
};

// srm的待办及已办
export const getSRMTasks = async (params) => {
  return await request.get({
    url:
      "/admin-api/portal/todo/srm?workcode=" +
      params.id +
      "&pageNo=" +
      params.pageNum +
      "&pageSize=" +
      params.pageSize,
  });
};

// CMR消息通知
export const getNotifyMessages = async (id) => {
  return await request.get({
    url: "/admin-api/portal/todo/crm/notice?workcode=" + id,
  });
};

// CRM消息列表
export const getNotifyMessageList = async (id) => {
  return await request.get({
    url: "/admin-api/portal/todo/crm/notice/self?workcode=" + id,
  });
};

// CRM标记消息为已读
export const markMessageAsRead = async (id) => {
  return await request.get({
    url: "/admin-api/portal/todo/crm/notice/readed?workcode=" + id,
  });
};

// OA消息通知
export const getOANotifyMessages = async (id) => {
  return await request.get({
    url: "/admin-api/portal/todo/oa/notice?workcode=" + id,
  });
};

// OA消息列表
export const getOANotifyMessageList = async (id) => {
  return await request.get({
    url: "/admin-api/portal/todo/oa/notice/self?workcode=" + id, // /portal/todo/oa/notice/self
  });
};

// OA标记消息为已读
export const markOAMessageAsRead = async (id) => {
  return await request.get({
    url: "/admin-api/portal/todo/oa/notice/readed?workcode=" + id, // portal/todo/oa/notice/readed
  });
};

// SRM消息通知
export const getSRMNotifyMessages = async (id) => {
  return await request.get({
    url: "/admin-api/portal/todo/srm/notice?workcode=" + id,
  });
};

// SRM消息列表
export const getSRMNotifyMessageList = async (id) => {
  return await request.get({
    url: "/admin-api/portal/todo/srm/notice/self?workcode=" + id,
  });
};

// SRM 标为已读
export const markSRMNotifyMessageRead = async (id) => {
  return await request.get({
    url: "/admin-api/portal/todo/srm/notice/readed?workcode=" + id,
  });
};

// 首页公告
export const getNotices = async (params) => {
  return await request.get({
    url:
      "/admin-api/portal/home/notice?pageNo=" +
      params.pageNum +
      "&pageSize=" +
      params.pageSize,
  });
};

// 红头文件
export const getRedHeadFiles = async (params) => {
  return await request.get({
    url:
      "/admin-api/portal/home/red?pageNo=" +
      params.pageNum +
      "&pageSize=" +
      params.pageSize,
  });
};

// 新闻资讯
export const getNews = async (params) => {
  return await request.get({
    url:
      "/admin-api/portal/home/news?pageNo=" +
      params.pageNum +
      "&pageSize=" +
      params.pageSize,
  });
};
