import routes from "@/routes";
import { getAuthHeaders } from "../utils";

export interface Payload {
  token: string;
}

export interface Response {
  ai_assistants: IAssistant[];
}

export interface IAssistant {
  id: number;
  name: string;
  external_id: string;
  external_chat_id: string | null;
  photo: {
    th: string;
    th2x: string;
    lg: string;
  };
  photo_mime_type: string;
  created_at: string;
  updated_at: string;
  expirience: string;
  rating: string;
  stars: number;
}

export interface PayloadSetExternalChatId extends Payload {
  chatId: string;
  ai_assistant_chat: {
    external_id: string;
  };
}

export interface ResponseSetExternalChatId {
  ai_assistant_chat: {
    id: number;
    assistant_id: number;
    external_id: string;
    created_at: string;
    updated_at: string;
  };
}

export const createRequest = ({ token }: Payload): Request => {
  const url = new URL(routes.server.assistants());

  return new Request(url, { method: "GET", headers: getAuthHeaders(token) });
};

export const createRequestSetExternalChatId = ({
  token,
  ai_assistant_chat,
  chatId,
}: PayloadSetExternalChatId) => {
  const url = new URL(routes.server.setExternalChatIdAssistants(chatId));
  const body = JSON.stringify({ ai_assistant_chat });
  return new Request(url, {
    method: "POST",
    headers: getAuthHeaders(token),
    body,
  });
};
