
import type { CurrentUser } from '@/models/user';
import request from '@/utils/request';

export async function query(): Promise<any> { // 根据用户token获取用户信息
  const data = await request(`/Logging/GetPassportInfoByToken`, {
    method: 'GET',
  })
  if (data.Result_Code !== 100) {
    return { code: data.Result_Code, msg: data.Result_Data }
  }
  return data.Result_Data;
}

export async function queryCurrent(UserIdEncrypted: string | number): Promise<CurrentUser | { code: number, msg: string }> {

  const data = await request(`/Logging/GetPassportInfoById?UserIdEncrypted=${UserIdEncrypted}`, {
    method: 'GET',
  })

  if (data.Result_Code !== 100) { // 登录超时
    return { code: data.Result_Code, msg: data.Result_Data }
  }
  return data.Result_Data;
}
// 获取消息队列
export async function queryNotices(params: any): Promise<any> {
 
  const data = await request('/Platform/GetMessageList',{ // 只获取未读的通知
    method: 'POST',
    data: {SearchParameter:{...params,MESSAGE_STATE:1},pageIndex:1,pageSize: 99,SortStr: 'MESSAGE_STATE asc,OPERATE_DATE desc'}
  });
  if (data.Result_Code !== 100) { // 登录超时
    return []
  }
  return data.Result_Data.List;
}

// 消息状态更新
export async function changeNoticesState(params: any): Promise<boolean> {
 
  const data = await request('/Platform/SynchroMessage',{
    method: 'POST',
    data: {...params}
  });
  if (data.Result_Code !== 100) { // 登录超时
    return false
  }
  return true;
}
// 消息状态更新
export async function setMessageState(params: {
  messageIds: string,
  recStaffId: number,
  messageState: number
}): Promise<boolean> {
 
  const data = await request('/Platform/SetMessageState',{
    method: 'POST',
    data: {...params}
  });
  if (data.Result_Code !== 100) { // 更新失败
    return false
  }
  return true;
}

// 获取用户平台左侧菜单数据
export async function getUserMenu(userid?: number): Promise<any[]> {

  const data = await request(`/FrameWork/GetUserModuleList?userid=${userid}`, {
    method: 'GET',
  });
  if (data.Result_Code !== 100) {
    return [];
  }

  return data.Result_Data.List;
}
// 添加用户行为记录
export function synchroBehaviorRecord(data: any): void {

  request(`/Platform/SynchroBehaviorrecord`, {
    method: 'POST',
    data
  });

}

// 添加用户行为具体接口的
export function SynchroBEHAVIORRECORD(data: any): void {

  request(`/Platform/SynchroBEHAVIORRECORD`, {
    method: 'POST',
    data
  });

}