import api from 'src/config/api';
import { type InstanceData } from 'src/types/instance';

export const createInstance = (data: FormData) =>
  api.post<InstanceData>('instances', data);

export const getInviteCodeWithToken = async (id: number, token: string) => {
  const response = await api.get(`/instances/${id}/code`, {
    headers: { Authorization: `Bearer ${token}` },
  });
  return response.data.code;
};

export const getInviteCode = async (id: number) => {
  const response = await api.get(`/instances/${id}/code`);
  return response.data.code;
};

export const unableInviteCodeWithToken = (id: number, token: string) =>
  api.patch(
    `/instances/${id}/inviteLink`,
    {},
    {
      headers: { Authorization: `Bearer ${token}` },
    },
  );

export const unableInviteCode = (id: number) =>
  api.patch(`/instances/${id}/inviteLink`);
