import {
  AddFileParamsSwagger,
  AddMinioParamsSwagger,
} from "@/components/models/management/ExternalAuthController";
import { request } from "@/components/service/index";

export const ExternalAuthControllerService = {
  signIn: (id: string, password: string) => {
    return request.post("/api/external-auth/signin", { id, password });
  },

  add: (params: AddFileParamsSwagger, file: File | Blob) => {
    const fd = new FormData();
    fd.append("file", file);
    const { authId, ...rest } = params as any;
    const snakeParams = { ...rest, auth_id: authId };

    return request.postWithConfig("/api/external-auth/register-with-file", fd, {
      params: snakeParams,
    });
  },

  addMinio: (params: AddMinioParamsSwagger) => {
    return request.postWithConfig(
      "/api/external-auth/register-with-minio-file",
      {},
      { params },
    );
  },
  swSearch: (id: string, token: string) => {
    return request.get("/api/external-auth/sw-search", {
      id,
      token,
    });
  },
  edgeSearch: (id: string, token: string) => {
    return request.get("/api/external-auth/edge-search", {
      id,
      token,
    });
  },
};
