export enum EContentType {
  TextPlain = 'text/plain',
  ApplicationJson = 'application/json',
  AiseekAudioChunk = 'aiseek/audio_chunk',
  AiseekThinking = 'aiseek/thinking',
  AiseekFunctionCall = 'aiseek/function_call',
  AiseekMultimodal = 'aiseek/multimodal',
  AiseekQA = 'aiseek/qa'
}

export enum EChatRole {
  System = 'system',
  User = 'user',
  Assistant = 'assistant',
  Function = 'function',
  Tool = 'tool'
}

// 导出对应的联合类型
// export type TChatRole = `${ChatRole}`; // TypeScript 4.1+ 模板字面量类型
// 或兼容写法：
export type TChatRole = EChatRole[keyof EChatRole];

export type TContentType = EContentType[keyof EContentType];


// contentType === "aiseek/qa" 消息体内容
export type TMessageBodyContent = {
  answer: {
      "payload": {
          "links": string[],
          "pics": string[]
      },
      "text": string
  },
  audio?: string // "FwXHApoAmf5y/Z/+f/6A+yr5FftA+yH43PWe8y7zXPKK8lT0j/"
  format?: string //"pcm"
  sampleRate?:  number// 16000
  sentenceBegin?: string
  qaId: string
}
export type TMessageBody = {
  content: TMessageBodyContent,
  contentType: EContentType,
}

export type TMessage = {
  content: string|Record<string, any>,
  contentType?: EContentType
  dislikeReason?: string,
  isDislike?: boolean,
  isLike?: boolean,
  isStreaming?: boolean,
  msgId?: number,
  saveStatus?: number 
  msgTime?: string,
  msgUk: string,
  originalAgentId?: string,
  role: TChatRole,
  body?: TMessageBody
  sessionId?: string
  agentId?: string
}

export type TRobotMessage = {
  reasoningContent: string
  role:  TChatRole
  robot?: {
    avatar: string;
    agentId: string;
    name: string;
  };
} & Omit<TMessage, 'role'> ;

export type TAnyMessage = TMessage | TRobotMessage;






export type TRequestMessage = {
  content: any;
  contentType: TContentType;
  role: TChatRole;
};

export type TRequestBody = {
  agentId: string;
  isEnableOutputAudioStream: boolean;
  isEnableSearch: boolean;
  isEnableThinking: boolean;
  loginId: string;
  messages: (TAnyMessage|TRequestMessage)[];
  sessionId: string;
};

export type TAppendMessage  = {
    content: any,
    contentType: TContentType,
    isStreaming: boolean,
    msgUk: string,
    saveStatus: number,  //0|1|2
    role: TChatRole
} & TAnyMessage
export type TAppendMessages = {
  agentId: string,
  loginId: string,
  messages: TAppendMessage[],
  sessionId: string
}

export type TMessageHistories = {
  data: TMessage|TRobotMessage[];
  nextId: string;
  totalCount: number|null;
};