/**
 * Agravity OpenAPI Documentation - Public Functions
 *
 * Contact: support@agravity.io
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */
/* tslint:disable:no-unused-variable member-ordering */

import { Inject, Injectable, Optional } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams, HttpResponse, HttpEvent, HttpContext } from '@angular/common/http';
import { Observable } from 'rxjs';
import { OpenApiHttpParams, QueryParamStyle } from '../query.params';

// @ts-ignore
import { AgravityErrorResponse } from '../model/agravityErrorResponse.pub.agravity';
// @ts-ignore
import { SearchAdminStatus } from '../model/searchAdminStatus.pub.agravity';
// @ts-ignore
import { SearchFacet } from '../model/searchFacet.pub.agravity';
// @ts-ignore
import { SearchResult } from '../model/searchResult.pub.agravity';

// @ts-ignore
import { BASE_PATH, COLLECTION_FORMATS } from '../variables';
import { AgravityPublicConfiguration } from '../configuration';
import { BaseService } from '../api.base.service';

export interface HttpGetSearchFacetteByNameRequestParams {
	/** The name of the facette. */
	name: string;
	/** The search string which should be found. */
	s: string;
	/** Limits the result on all collections from the given collectiontypeid parameter. */
	collectiontypeid?: string;
	/** Limits the result on collection id (and siblings). Will be overwritten by collectiontypeid parameter. */
	collectionid?: string;
	/** Two modes supported: \&quot;any\&quot; or \&quot;all\&quot; search terms should be applied. (Only if Azure Search is enabled) */
	mode?: string;
	/** Key value filter for filterable strings and string collections separated by special \&#39;,,,\&#39;. For date or numbers \&quot;&lt;\&quot;, \&quot;&#x3D;\&quot; and \&quot;&gt;\&quot; are possible. Mode influences AND (all) and OR (any) of all filters. Multiple filters are separated by semicolons. (Only if Azure Search is enabled) */
	filter?: string;
	/** Colon separated key value filter for additional scopes. It applies the same conventions as for filter parameter. */
	scopefilter?: string;
	/** Comma separated values list with all ids which should be returned. */
	ids?: string;
	/** If the search should be redirected to a specific portal. */
	portalId?: string;
}

export interface HttpGlobalSearchRequestParams {
	/** The search string which should be found. */
	s: string;
	/** How many results should be returend. 0 is backend configuration limit. */
	limit?: number;
	/** (default: 0) - Used for paging - how many items should be skipped before next limit results will be fetched. */
	skip?: number;
	/** Limits the result on all collections from the given collectiontypeid parameter. */
	collectiontypeid?: string;
	/** Limits the result on collection id (and siblings). Will be overwritten by collectiontypeid parameter. */
	collectionid?: string;
	/** Two modes supported: \&quot;any\&quot; or \&quot;all\&quot; search terms should be applied. (Only if Azure Search is enabled) */
	mode?: string;
	/** This will expose the thumbnail asset blob incl. URL with SAS Token. */
	expose?: boolean;
	/** Colon separated key value filter for filterable strings and string collections. For date or numbers \&quot;&lt;\&quot;, \&quot;&#x3D;\&quot; and \&quot;&gt;\&quot; are possible. Mode influences AND (all) and OR (any) of all filters. Multiple filters are separated by semicolons. (Only if Azure Search is enabled) */
	filter?: string;
	/** Search Broadness: Can be 0, 1 or 2. (0 is the most exact search, 2 is the broadest search) (1, 2 is with AI) */
	broadness?: number;
	/** The ID of the relation which this search is limited to. (Only the assets in this relation are returend) */
	relId?: string;
	/** Colon separated key value filter for additional scopes. It applies the same conventions as for filter parameter. */
	scopefilter?: string;
	/** Sortable fields can be used. For descendant sorting use leading \&quot;!\&quot;. (Only if Azure Search is enabled) */
	orderby?: string;
	/** Comma separated values list with all ids which should be returned. */
	ids?: string;
	/** If the search should be redirected to a specific portal. */
	portalId?: string;
	/** When default language should be returned and the translation dictionary is delivered. (Ignores the \&quot;Accept-Language\&quot; header) */
	translations?: boolean;
	/** The requested language of the response. If not matching it falls back to default language. */
	acceptLanguage?: string;
}

export interface HttpSearchAdminGetStatusRequestParams {
	/** If the search should be redirected to a specific portal. */
	portalId?: string;
}

@Injectable({
	providedIn: 'root'
})
export class PublicSearchManagementService extends BaseService {
	constructor(
		protected httpClient: HttpClient,
		@Optional() @Inject(BASE_PATH) basePath: string | string[],
		@Optional() configuration?: AgravityPublicConfiguration
	) {
		super(basePath, configuration);
	}

	/**
	 * This endpoint returns one facette based on the search parameters.
	 * @endpoint get /search/facette
	 * @param requestParameters
	 * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
	 * @param reportProgress flag to report request and response progress.
	 * @param options additional options
	 */
	public httpGetSearchFacetteByName(
		requestParameters: HttpGetSearchFacetteByNameRequestParams,
		observe?: 'body',
		reportProgress?: boolean,
		options?: { httpHeaderAccept?: 'application/json'; context?: HttpContext; transferCache?: boolean }
	): Observable<SearchFacet>;
	public httpGetSearchFacetteByName(
		requestParameters: HttpGetSearchFacetteByNameRequestParams,
		observe?: 'response',
		reportProgress?: boolean,
		options?: { httpHeaderAccept?: 'application/json'; context?: HttpContext; transferCache?: boolean }
	): Observable<HttpResponse<SearchFacet>>;
	public httpGetSearchFacetteByName(
		requestParameters: HttpGetSearchFacetteByNameRequestParams,
		observe?: 'events',
		reportProgress?: boolean,
		options?: { httpHeaderAccept?: 'application/json'; context?: HttpContext; transferCache?: boolean }
	): Observable<HttpEvent<SearchFacet>>;
	public httpGetSearchFacetteByName(
		requestParameters: HttpGetSearchFacetteByNameRequestParams,
		observe: any = 'body',
		reportProgress: boolean = false,
		options?: { httpHeaderAccept?: 'application/json'; context?: HttpContext; transferCache?: boolean }
	): Observable<any> {
		const name = requestParameters?.name;
		if (name === null || name === undefined) {
			throw new Error('Required parameter name was null or undefined when calling httpGetSearchFacetteByName.');
		}
		const s = requestParameters?.s;
		if (s === null || s === undefined) {
			throw new Error('Required parameter s was null or undefined when calling httpGetSearchFacetteByName.');
		}
		const collectiontypeid = requestParameters?.collectiontypeid;
		const collectionid = requestParameters?.collectionid;
		const mode = requestParameters?.mode;
		const filter = requestParameters?.filter;
		const scopefilter = requestParameters?.scopefilter;
		const ids = requestParameters?.ids;
		const portalId = requestParameters?.portalId;

		let localVarQueryParameters = new OpenApiHttpParams(this.encoder);

		localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, 'name', <any>name, QueryParamStyle.Form, true);

		localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, 's', <any>s, QueryParamStyle.Form, true);

		localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, 'collectiontypeid', <any>collectiontypeid, QueryParamStyle.Form, true);

		localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, 'collectionid', <any>collectionid, QueryParamStyle.Form, true);

		localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, 'mode', <any>mode, QueryParamStyle.Form, true);

		localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, 'filter', <any>filter, QueryParamStyle.Form, true);

		localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, 'scopefilter', <any>scopefilter, QueryParamStyle.Form, true);

		localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, 'ids', <any>ids, QueryParamStyle.Form, true);

		localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, 'portal_id', <any>portalId, QueryParamStyle.Form, true);

		let localVarHeaders = this.defaultHeaders;

		// authentication (function_key) required
		localVarHeaders = this.configuration.addCredentialToHeaders('function_key', 'x-functions-key', localVarHeaders);

		const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept(['application/json']);
		if (localVarHttpHeaderAcceptSelected !== undefined) {
			localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected);
		}

		const localVarHttpContext: HttpContext = options?.context ?? new HttpContext();

		const localVarTransferCache: boolean = options?.transferCache ?? true;

		let responseType_: 'text' | 'json' | 'blob' = 'json';
		if (localVarHttpHeaderAcceptSelected) {
			if (localVarHttpHeaderAcceptSelected.startsWith('text')) {
				responseType_ = 'text';
			} else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) {
				responseType_ = 'json';
			} else {
				responseType_ = 'blob';
			}
		}

		let localVarPath = `/search/facette`;
		const { basePath, withCredentials } = this.configuration;
		return this.httpClient.request<SearchFacet>('get', `${basePath}${localVarPath}`, {
			context: localVarHttpContext,
			params: localVarQueryParameters.toHttpParams(),
			responseType: <any>responseType_,
			...(withCredentials ? { withCredentials } : {}),
			headers: localVarHeaders,
			observe: observe,
			...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}),
			reportProgress: reportProgress
		});
	}

	/**
	 * This endpoint returns a configured max amount of results for search terms.
	 * @endpoint get /search
	 * @param requestParameters
	 * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
	 * @param reportProgress flag to report request and response progress.
	 * @param options additional options
	 */
	public httpGlobalSearch(
		requestParameters: HttpGlobalSearchRequestParams,
		observe?: 'body',
		reportProgress?: boolean,
		options?: { httpHeaderAccept?: 'application/json'; context?: HttpContext; transferCache?: boolean }
	): Observable<SearchResult>;
	public httpGlobalSearch(
		requestParameters: HttpGlobalSearchRequestParams,
		observe?: 'response',
		reportProgress?: boolean,
		options?: { httpHeaderAccept?: 'application/json'; context?: HttpContext; transferCache?: boolean }
	): Observable<HttpResponse<SearchResult>>;
	public httpGlobalSearch(
		requestParameters: HttpGlobalSearchRequestParams,
		observe?: 'events',
		reportProgress?: boolean,
		options?: { httpHeaderAccept?: 'application/json'; context?: HttpContext; transferCache?: boolean }
	): Observable<HttpEvent<SearchResult>>;
	public httpGlobalSearch(
		requestParameters: HttpGlobalSearchRequestParams,
		observe: any = 'body',
		reportProgress: boolean = false,
		options?: { httpHeaderAccept?: 'application/json'; context?: HttpContext; transferCache?: boolean }
	): Observable<any> {
		const s = requestParameters?.s;
		if (s === null || s === undefined) {
			throw new Error('Required parameter s was null or undefined when calling httpGlobalSearch.');
		}
		const limit = requestParameters?.limit;
		const skip = requestParameters?.skip;
		const collectiontypeid = requestParameters?.collectiontypeid;
		const collectionid = requestParameters?.collectionid;
		const mode = requestParameters?.mode;
		const expose = requestParameters?.expose;
		const filter = requestParameters?.filter;
		const broadness = requestParameters?.broadness;
		const relId = requestParameters?.relId;
		const scopefilter = requestParameters?.scopefilter;
		const orderby = requestParameters?.orderby;
		const ids = requestParameters?.ids;
		const portalId = requestParameters?.portalId;
		const translations = requestParameters?.translations;
		const acceptLanguage = requestParameters?.acceptLanguage;

		let localVarQueryParameters = new OpenApiHttpParams(this.encoder);

		localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, 's', <any>s, QueryParamStyle.Form, true);

		localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, 'limit', <any>limit, QueryParamStyle.Form, true);

		localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, 'skip', <any>skip, QueryParamStyle.Form, true);

		localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, 'collectiontypeid', <any>collectiontypeid, QueryParamStyle.Form, true);

		localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, 'collectionid', <any>collectionid, QueryParamStyle.Form, true);

		localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, 'mode', <any>mode, QueryParamStyle.Form, true);

		localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, 'expose', <any>expose, QueryParamStyle.Form, true);

		localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, 'filter', <any>filter, QueryParamStyle.Form, true);

		localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, 'broadness', <any>broadness, QueryParamStyle.Form, true);

		localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, 'rel_id', <any>relId, QueryParamStyle.Form, true);

		localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, 'scopefilter', <any>scopefilter, QueryParamStyle.Form, true);

		localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, 'orderby', <any>orderby, QueryParamStyle.Form, true);

		localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, 'ids', <any>ids, QueryParamStyle.Form, true);

		localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, 'portal_id', <any>portalId, QueryParamStyle.Form, true);

		localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, 'translations', <any>translations, QueryParamStyle.Form, true);

		let localVarHeaders = this.defaultHeaders;
		if (acceptLanguage !== undefined && acceptLanguage !== null) {
			localVarHeaders = localVarHeaders.set('Accept-Language', String(acceptLanguage));
		}

		// authentication (function_key) required
		localVarHeaders = this.configuration.addCredentialToHeaders('function_key', 'x-functions-key', localVarHeaders);

		const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept(['application/json']);
		if (localVarHttpHeaderAcceptSelected !== undefined) {
			localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected);
		}

		const localVarHttpContext: HttpContext = options?.context ?? new HttpContext();

		const localVarTransferCache: boolean = options?.transferCache ?? true;

		let responseType_: 'text' | 'json' | 'blob' = 'json';
		if (localVarHttpHeaderAcceptSelected) {
			if (localVarHttpHeaderAcceptSelected.startsWith('text')) {
				responseType_ = 'text';
			} else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) {
				responseType_ = 'json';
			} else {
				responseType_ = 'blob';
			}
		}

		let localVarPath = `/search`;
		const { basePath, withCredentials } = this.configuration;
		return this.httpClient.request<SearchResult>('get', `${basePath}${localVarPath}`, {
			context: localVarHttpContext,
			params: localVarQueryParameters.toHttpParams(),
			responseType: <any>responseType_,
			...(withCredentials ? { withCredentials } : {}),
			headers: localVarHeaders,
			observe: observe,
			...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}),
			reportProgress: reportProgress
		});
	}

	/**
	 * This endpoint gives the status about the index and indexer.
	 * @endpoint get /searchadmin/status
	 * @param requestParameters
	 * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
	 * @param reportProgress flag to report request and response progress.
	 * @param options additional options
	 */
	public httpSearchAdminGetStatus(
		requestParameters?: HttpSearchAdminGetStatusRequestParams,
		observe?: 'body',
		reportProgress?: boolean,
		options?: { httpHeaderAccept?: 'application/json'; context?: HttpContext; transferCache?: boolean }
	): Observable<SearchAdminStatus>;
	public httpSearchAdminGetStatus(
		requestParameters?: HttpSearchAdminGetStatusRequestParams,
		observe?: 'response',
		reportProgress?: boolean,
		options?: { httpHeaderAccept?: 'application/json'; context?: HttpContext; transferCache?: boolean }
	): Observable<HttpResponse<SearchAdminStatus>>;
	public httpSearchAdminGetStatus(
		requestParameters?: HttpSearchAdminGetStatusRequestParams,
		observe?: 'events',
		reportProgress?: boolean,
		options?: { httpHeaderAccept?: 'application/json'; context?: HttpContext; transferCache?: boolean }
	): Observable<HttpEvent<SearchAdminStatus>>;
	public httpSearchAdminGetStatus(
		requestParameters?: HttpSearchAdminGetStatusRequestParams,
		observe: any = 'body',
		reportProgress: boolean = false,
		options?: { httpHeaderAccept?: 'application/json'; context?: HttpContext; transferCache?: boolean }
	): Observable<any> {
		const portalId = requestParameters?.portalId;

		let localVarQueryParameters = new OpenApiHttpParams(this.encoder);

		localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, 'portal_id', <any>portalId, QueryParamStyle.Form, true);

		let localVarHeaders = this.defaultHeaders;

		// authentication (function_key) required
		localVarHeaders = this.configuration.addCredentialToHeaders('function_key', 'x-functions-key', localVarHeaders);

		const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept(['application/json']);
		if (localVarHttpHeaderAcceptSelected !== undefined) {
			localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected);
		}

		const localVarHttpContext: HttpContext = options?.context ?? new HttpContext();

		const localVarTransferCache: boolean = options?.transferCache ?? true;

		let responseType_: 'text' | 'json' | 'blob' = 'json';
		if (localVarHttpHeaderAcceptSelected) {
			if (localVarHttpHeaderAcceptSelected.startsWith('text')) {
				responseType_ = 'text';
			} else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) {
				responseType_ = 'json';
			} else {
				responseType_ = 'blob';
			}
		}

		let localVarPath = `/searchadmin/status`;
		const { basePath, withCredentials } = this.configuration;
		return this.httpClient.request<SearchAdminStatus>('get', `${basePath}${localVarPath}`, {
			context: localVarHttpContext,
			params: localVarQueryParameters.toHttpParams(),
			responseType: <any>responseType_,
			...(withCredentials ? { withCredentials } : {}),
			headers: localVarHeaders,
			observe: observe,
			...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}),
			reportProgress: reportProgress
		});
	}
}
