import {
  BaseMetorialEndpoint,
  MetorialEndpointManager
} from '@metorial/util-endpoint';

import {
  mapDashboardInstanceMagicMcpGroupsAddServersBody,
  mapDashboardInstanceMagicMcpGroupsAddServersOutput,
  mapDashboardInstanceMagicMcpGroupsCreateBody,
  mapDashboardInstanceMagicMcpGroupsCreateOutput,
  mapDashboardInstanceMagicMcpGroupsDeleteOutput,
  mapDashboardInstanceMagicMcpGroupsGetOutput,
  mapDashboardInstanceMagicMcpGroupsListOutput,
  mapDashboardInstanceMagicMcpGroupsListQuery,
  mapDashboardInstanceMagicMcpGroupsRemoveServersBody,
  mapDashboardInstanceMagicMcpGroupsRemoveServersOutput,
  mapDashboardInstanceMagicMcpGroupsUpdateBody,
  mapDashboardInstanceMagicMcpGroupsUpdateOutput,
  type DashboardInstanceMagicMcpGroupsAddServersBody,
  type DashboardInstanceMagicMcpGroupsAddServersOutput,
  type DashboardInstanceMagicMcpGroupsCreateBody,
  type DashboardInstanceMagicMcpGroupsCreateOutput,
  type DashboardInstanceMagicMcpGroupsDeleteOutput,
  type DashboardInstanceMagicMcpGroupsGetOutput,
  type DashboardInstanceMagicMcpGroupsListOutput,
  type DashboardInstanceMagicMcpGroupsListQuery,
  type DashboardInstanceMagicMcpGroupsRemoveServersBody,
  type DashboardInstanceMagicMcpGroupsRemoveServersOutput,
  type DashboardInstanceMagicMcpGroupsUpdateBody,
  type DashboardInstanceMagicMcpGroupsUpdateOutput
} from '../resources';

/**
 * @name Magic MCP Groups controller
 * @description Magic MCP groups categorize servers and can be bound to token access.
 *
 * @see https://metorial.com/api
 * @see https://metorial.com/docs
 */
export class MetorialManagementInstanceMagicMcpGroupsEndpoint {
  constructor(private readonly _manager: MetorialEndpointManager<any>) {}

  // thin proxies so method bodies stay unchanged
  private _get(request: any) {
    return this._manager._get(request);
  }
  private _post(request: any) {
    return this._manager._post(request);
  }
  private _put(request: any) {
    return this._manager._put(request);
  }
  private _patch(request: any) {
    return this._manager._patch(request);
  }
  private _delete(request: any) {
    return this._manager._delete(request);
  }

  /**
   * @name List magic MCP groups
   * @description Returns a paginated list of magic MCP groups.
   *
   * @param `instanceId` - string
   * @param `query` - DashboardInstanceMagicMcpGroupsListQuery
   * @param `opts` - { headers?: Record<string, string> }
   * @returns DashboardInstanceMagicMcpGroupsListOutput
   * @see https://metorial.com/api
   * @see https://metorial.com/docs
   */
  list(
    instanceId: string,
    query?: DashboardInstanceMagicMcpGroupsListQuery,
    opts?: { headers?: Record<string, string> }
  ): Promise<DashboardInstanceMagicMcpGroupsListOutput> {
    let path = `instances/${instanceId}/magic-mcp-groups`;

    let request = {
      path,

      query: query
        ? mapDashboardInstanceMagicMcpGroupsListQuery.transformTo(query)
        : undefined,
      ...(opts?.headers ? { headers: opts.headers } : {})
    } as any;

    return this._get(request).transform(
      mapDashboardInstanceMagicMcpGroupsListOutput
    );
  }

  /**
   * @name Get magic MCP group
   * @description Retrieves a specific magic MCP group.
   *
   * @param `instanceId` - string
   * @param `magicMcpGroupId` - string
   * @param `opts` - { headers?: Record<string, string> }
   * @returns DashboardInstanceMagicMcpGroupsGetOutput
   * @see https://metorial.com/api
   * @see https://metorial.com/docs
   */
  get(
    instanceId: string,
    magicMcpGroupId: string,
    opts?: { headers?: Record<string, string> }
  ): Promise<DashboardInstanceMagicMcpGroupsGetOutput> {
    let path = `instances/${instanceId}/magic-mcp-groups/${magicMcpGroupId}`;

    let request = {
      path,

      ...(opts?.headers ? { headers: opts.headers } : {})
    } as any;

    return this._get(request).transform(
      mapDashboardInstanceMagicMcpGroupsGetOutput
    );
  }

  /**
   * @name Create magic MCP group
   * @description Creates a magic MCP group.
   *
   * @param `instanceId` - string
   * @param `body` - DashboardInstanceMagicMcpGroupsCreateBody
   * @param `opts` - { headers?: Record<string, string> }
   * @returns DashboardInstanceMagicMcpGroupsCreateOutput
   * @see https://metorial.com/api
   * @see https://metorial.com/docs
   */
  create(
    instanceId: string,
    body: DashboardInstanceMagicMcpGroupsCreateBody,
    opts?: { headers?: Record<string, string> }
  ): Promise<DashboardInstanceMagicMcpGroupsCreateOutput> {
    let path = `instances/${instanceId}/magic-mcp-groups`;

    let request = {
      path,
      body: mapDashboardInstanceMagicMcpGroupsCreateBody.transformTo(body),

      ...(opts?.headers ? { headers: opts.headers } : {})
    } as any;

    return this._post(request).transform(
      mapDashboardInstanceMagicMcpGroupsCreateOutput
    );
  }

  /**
   * @name Delete magic MCP group
   * @description Deletes a magic MCP group.
   *
   * @param `instanceId` - string
   * @param `magicMcpGroupId` - string
   * @param `opts` - { headers?: Record<string, string> }
   * @returns DashboardInstanceMagicMcpGroupsDeleteOutput
   * @see https://metorial.com/api
   * @see https://metorial.com/docs
   */
  delete(
    instanceId: string,
    magicMcpGroupId: string,
    opts?: { headers?: Record<string, string> }
  ): Promise<DashboardInstanceMagicMcpGroupsDeleteOutput> {
    let path = `instances/${instanceId}/magic-mcp-groups/${magicMcpGroupId}`;

    let request = {
      path,

      ...(opts?.headers ? { headers: opts.headers } : {})
    } as any;

    return this._delete(request).transform(
      mapDashboardInstanceMagicMcpGroupsDeleteOutput
    );
  }

  /**
   * @name Update magic MCP group
   * @description Updates a magic MCP group.
   *
   * @param `instanceId` - string
   * @param `magicMcpGroupId` - string
   * @param `body` - DashboardInstanceMagicMcpGroupsUpdateBody
   * @param `opts` - { headers?: Record<string, string> }
   * @returns DashboardInstanceMagicMcpGroupsUpdateOutput
   * @see https://metorial.com/api
   * @see https://metorial.com/docs
   */
  update(
    instanceId: string,
    magicMcpGroupId: string,
    body: DashboardInstanceMagicMcpGroupsUpdateBody,
    opts?: { headers?: Record<string, string> }
  ): Promise<DashboardInstanceMagicMcpGroupsUpdateOutput> {
    let path = `instances/${instanceId}/magic-mcp-groups/${magicMcpGroupId}`;

    let request = {
      path,
      body: mapDashboardInstanceMagicMcpGroupsUpdateBody.transformTo(body),

      ...(opts?.headers ? { headers: opts.headers } : {})
    } as any;

    return this._patch(request).transform(
      mapDashboardInstanceMagicMcpGroupsUpdateOutput
    );
  }

  /**
   * @name Add servers to magic MCP group
   * @description Adds magic MCP servers to a group.
   *
   * @param `instanceId` - string
   * @param `magicMcpGroupId` - string
   * @param `body` - DashboardInstanceMagicMcpGroupsAddServersBody
   * @param `opts` - { headers?: Record<string, string> }
   * @returns DashboardInstanceMagicMcpGroupsAddServersOutput
   * @see https://metorial.com/api
   * @see https://metorial.com/docs
   */
  addServers(
    instanceId: string,
    magicMcpGroupId: string,
    body: DashboardInstanceMagicMcpGroupsAddServersBody,
    opts?: { headers?: Record<string, string> }
  ): Promise<DashboardInstanceMagicMcpGroupsAddServersOutput> {
    let path = `instances/${instanceId}/magic-mcp-groups/${magicMcpGroupId}/add-servers`;

    let request = {
      path,
      body: mapDashboardInstanceMagicMcpGroupsAddServersBody.transformTo(body),

      ...(opts?.headers ? { headers: opts.headers } : {})
    } as any;

    return this._post(request).transform(
      mapDashboardInstanceMagicMcpGroupsAddServersOutput
    );
  }

  /**
   * @name Remove servers from magic MCP group
   * @description Removes magic MCP servers from a group.
   *
   * @param `instanceId` - string
   * @param `magicMcpGroupId` - string
   * @param `body` - DashboardInstanceMagicMcpGroupsRemoveServersBody
   * @param `opts` - { headers?: Record<string, string> }
   * @returns DashboardInstanceMagicMcpGroupsRemoveServersOutput
   * @see https://metorial.com/api
   * @see https://metorial.com/docs
   */
  removeServers(
    instanceId: string,
    magicMcpGroupId: string,
    body: DashboardInstanceMagicMcpGroupsRemoveServersBody,
    opts?: { headers?: Record<string, string> }
  ): Promise<DashboardInstanceMagicMcpGroupsRemoveServersOutput> {
    let path = `instances/${instanceId}/magic-mcp-groups/${magicMcpGroupId}/remove-servers`;

    let request = {
      path,
      body: mapDashboardInstanceMagicMcpGroupsRemoveServersBody.transformTo(
        body
      ),

      ...(opts?.headers ? { headers: opts.headers } : {})
    } as any;

    return this._post(request).transform(
      mapDashboardInstanceMagicMcpGroupsRemoveServersOutput
    );
  }
}
