import request from '@/utils/request';
import { BaseResponse } from './type';
import { DA_HUA_URL_PREFIX } from '@/constants/constants';

export interface DAHUALoginParams {
  userName: string;
  signature: string;
  randomKey: string;
  encryptType: 'MD5';
  clientType: 'winpc';
  pid: 2548;
}

export interface DAHUADeviceParams {
  token: string;
}

export interface DAHUAKeepParams {
  token: string;
}

export interface DAHUAInfomationParams {
  token: string;
  [key: string]: any;
}

export interface DAHUADeviceParams {
  token: string;
  id: string;
  [key: string]: any;
}

export interface LoginResponse extends BaseResponse {
  token?: string;
  userId?: string | number;
}

export interface MeetingResponse extends BaseResponse {
  Id?: string;
}

export interface DAHUAMeetParams extends BaseResponse {
  token: string;
  name?: string; //会议名称
  masterId?: string; //主持人用户ID
  masterName?: string; //主持人名字
  masterNumber?: string; //主持人号码
  region: ''; //号码对应的PAAS域ID
  record: true; //是否录像录音true:录像录音 false:不录
  type?: string; //会议类型“audio”: 音频会议 “video”: 音视频会议
  mode: 'group'; //会议模式“p2p”:点对点“group”:群聊
}

export interface DAHUAMeetDeleteParams {
  token: string;
  meetId: string;
}

export interface DAHUAMemberParams {
  token: string;
  obj: {};
}

export interface KeepAliveResponse extends BaseResponse {}

export interface KeepMeetResponse extends BaseResponse {
  id?: string;
}

export const DAHUALogin = (params: DAHUALoginParams) =>
  request<LoginResponse>('POST', {
    url: `${DA_HUA_URL_PREFIX}/videoService/accounts/authorize`,
    data: params,
    headers: {
      'Content-Type': 'application/json',
      'X-Subject-Token': '',
    },
  });

export const DAHUAKeepAlive = (params: DAHUAKeepParams) =>{};
  // request<KeepAliveResponse>('PUT', {
  //   url: `${DA_HUA_URL_PREFIX}/videoService/accounts/token/keepalive`,
  //   data: params,
  //   headers: {
  //     'Content-Type': 'application/json',
  //     'X-Subject-Token': params.token,
  //   },
  // });


export const DAHUAUserInfo = (params: DAHUAKeepParams) =>
  request<BaseResponse>('GET', {
    url: `${DA_HUA_URL_PREFIX}/ras/user/info`,
    params: params,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
      'X-Subject-Token': params.token,
    },
  });

export const DAHUAInfomation = (params: DAHUAInfomationParams) =>
  request<BaseResponse>('POST', {
    url: `${DA_HUA_URL_PREFIX}/ras/acd/user/list`,
    data: params,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
      'X-Subject-Token': params.token,
    },
  });

export const DAHUACreateMeet = (params: DAHUAMeetParams) =>
  request<KeepMeetResponse>('POST', {
    url: `${DA_HUA_URL_PREFIX}/mcu/meeting`,
    data: params,
    headers: {
      'Content-Type': 'application/json',
      'X-Subject-Token': params.token,
    },
  });

export const DAHUADeleteMeet = (params: DAHUAMeetDeleteParams) =>
  request<KeepMeetResponse>('DELETE', {
    url: `${DA_HUA_URL_PREFIX}/mcu/meeting/` + params.meetId,
    headers: {
      'Content-Type': 'application/json',
      'X-Subject-Token': params.token,
    },
  });

export const DAHUAMeetingUser = (params: DAHUAMeetDeleteParams) =>
  request<KeepMeetResponse>('GET', {
    url: `${DA_HUA_URL_PREFIX}/mcu/meeting/` + params.meetId,
    headers: {
      'Content-Type': 'application/json',
      'X-Subject-Token': params.token,
    },
  });

export const DAHUADevice = (params: DAHUADeviceParams) =>
  request<BaseResponse>('GET', {
    url: `${DA_HUA_URL_PREFIX}/videoService/devicesManager/deviceTree`,
    params: params,
    headers: {
      'Content-Type': 'application/json',
      'X-Subject-Token': params.token,
    },
  });

export const DAHUAMeetingMember = (params: DAHUAMemberParams) =>
  request<BaseResponse>('POST', {
    url: `${DA_HUA_URL_PREFIX}/mcu/meeting/member`,
    data: params.obj,
    headers: {
      'Content-Type': 'application/json',
      'X-Subject-Token': params.token,
    },
  });

export const DAHUADeviceObj = (params: DAHUADeviceParams) =>
  request<BaseResponse>('GET', {
    url:
      `${DA_HUA_URL_PREFIX}/videoService/devicesManager/devices/` + params.id,
    headers: {
      'Content-Type': 'application/json',
      'X-Subject-Token': params.token,
    },
  });

export const DAHUAUserObj = (params: DAHUADeviceParams) =>
  request<BaseResponse>('GET', {
    url: `${DA_HUA_URL_PREFIX}/ras/user/` + params.id,
    headers: {
      'Content-Type': 'application/json',
      'X-Subject-Token': params.token,
    },
  });
