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

import {
  mapDashboardInstancePortalsConsumerProfilesAssignGroupsBody,
  mapDashboardInstancePortalsConsumerProfilesAssignGroupsOutput,
  mapDashboardInstancePortalsConsumerProfilesCreateBody,
  mapDashboardInstancePortalsConsumerProfilesCreateOutput,
  mapDashboardInstancePortalsConsumerProfilesGetOutput,
  mapDashboardInstancePortalsConsumerProfilesListOutput,
  mapDashboardInstancePortalsConsumerProfilesListQuery,
  mapDashboardInstancePortalsConsumerProfilesUnassignGroupsBody,
  mapDashboardInstancePortalsConsumerProfilesUnassignGroupsOutput,
  type DashboardInstancePortalsConsumerProfilesAssignGroupsBody,
  type DashboardInstancePortalsConsumerProfilesAssignGroupsOutput,
  type DashboardInstancePortalsConsumerProfilesCreateBody,
  type DashboardInstancePortalsConsumerProfilesCreateOutput,
  type DashboardInstancePortalsConsumerProfilesGetOutput,
  type DashboardInstancePortalsConsumerProfilesListOutput,
  type DashboardInstancePortalsConsumerProfilesListQuery,
  type DashboardInstancePortalsConsumerProfilesUnassignGroupsBody,
  type DashboardInstancePortalsConsumerProfilesUnassignGroupsOutput
} from '../resources';

/**
 * @name Portal Consumer Profiles controller
 * @description Manage the consumers and effective group assignments for a portal.
 *
 * @see https://metorial.com/api
 * @see https://metorial.com/docs
 */
export class MetorialDashboardInstancePortalsConsumerProfilesEndpoint {
  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 portal consumer profiles
   * @description Returns a paginated list of consumer profiles for a portal.
   *
   * @param `instanceId` - string
   * @param `portalId` - string
   * @param `query` - DashboardInstancePortalsConsumerProfilesListQuery
   * @param `opts` - { headers?: Record<string, string> }
   * @returns DashboardInstancePortalsConsumerProfilesListOutput
   * @see https://metorial.com/api
   * @see https://metorial.com/docs
   */
  list(
    instanceId: string,
    portalId: string,
    query?: DashboardInstancePortalsConsumerProfilesListQuery,
    opts?: { headers?: Record<string, string> }
  ): Promise<DashboardInstancePortalsConsumerProfilesListOutput> {
    let path = `dashboard/instances/${instanceId}/portals/${portalId}/consumer-profile`;

    let request = {
      path,

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

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

  /**
   * @name Get portal consumer profile
   * @description Retrieves a portal consumer profile by ID.
   *
   * @param `instanceId` - string
   * @param `portalId` - string
   * @param `consumerProfileId` - string
   * @param `opts` - { headers?: Record<string, string> }
   * @returns DashboardInstancePortalsConsumerProfilesGetOutput
   * @see https://metorial.com/api
   * @see https://metorial.com/docs
   */
  get(
    instanceId: string,
    portalId: string,
    consumerProfileId: string,
    opts?: { headers?: Record<string, string> }
  ): Promise<DashboardInstancePortalsConsumerProfilesGetOutput> {
    let path = `dashboard/instances/${instanceId}/portals/${portalId}/consumer-profile/${consumerProfileId}`;

    let request = {
      path,

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

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

  /**
   * @name Create portal consumer profile
   * @description Creates a new portal consumer profile.
   *
   * @param `instanceId` - string
   * @param `portalId` - string
   * @param `body` - DashboardInstancePortalsConsumerProfilesCreateBody
   * @param `opts` - { headers?: Record<string, string> }
   * @returns DashboardInstancePortalsConsumerProfilesCreateOutput
   * @see https://metorial.com/api
   * @see https://metorial.com/docs
   */
  create(
    instanceId: string,
    portalId: string,
    body: DashboardInstancePortalsConsumerProfilesCreateBody,
    opts?: { headers?: Record<string, string> }
  ): Promise<DashboardInstancePortalsConsumerProfilesCreateOutput> {
    let path = `dashboard/instances/${instanceId}/portals/${portalId}/consumer-profile`;

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

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

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

  /**
   * @name Assign portal consumer profile groups
   * @description Assigns one or more groups to a portal consumer profile.
   *
   * @param `instanceId` - string
   * @param `portalId` - string
   * @param `consumerProfileId` - string
   * @param `body` - DashboardInstancePortalsConsumerProfilesAssignGroupsBody
   * @param `opts` - { headers?: Record<string, string> }
   * @returns DashboardInstancePortalsConsumerProfilesAssignGroupsOutput
   * @see https://metorial.com/api
   * @see https://metorial.com/docs
   */
  assignGroups(
    instanceId: string,
    portalId: string,
    consumerProfileId: string,
    body: DashboardInstancePortalsConsumerProfilesAssignGroupsBody,
    opts?: { headers?: Record<string, string> }
  ): Promise<DashboardInstancePortalsConsumerProfilesAssignGroupsOutput> {
    let path = `dashboard/instances/${instanceId}/portals/${portalId}/consumer-profile/${consumerProfileId}/assign-groups`;

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

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

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

  /**
   * @name Unassign portal consumer profile groups
   * @description Removes one or more groups from a portal consumer profile.
   *
   * @param `instanceId` - string
   * @param `portalId` - string
   * @param `consumerProfileId` - string
   * @param `body` - DashboardInstancePortalsConsumerProfilesUnassignGroupsBody
   * @param `opts` - { headers?: Record<string, string> }
   * @returns DashboardInstancePortalsConsumerProfilesUnassignGroupsOutput
   * @see https://metorial.com/api
   * @see https://metorial.com/docs
   */
  unassignGroups(
    instanceId: string,
    portalId: string,
    consumerProfileId: string,
    body: DashboardInstancePortalsConsumerProfilesUnassignGroupsBody,
    opts?: { headers?: Record<string, string> }
  ): Promise<DashboardInstancePortalsConsumerProfilesUnassignGroupsOutput> {
    let path = `dashboard/instances/${instanceId}/portals/${portalId}/consumer-profile/${consumerProfileId}/unassign-groups`;

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

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

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