/**
 * Geographic Site Management
 * ** TMF API Reference : TMF 674 - Place - Geographic Site Management  ### August 2021  This API covers the operations to manage (create, read, delete) sites that can be associated to a customer, an account, a service delivery or other entities. It defines a Site as a convenience class that allows to easily refer to places important to other entities, where a geographic place is the entity that can answer the question “where?”, allowing to determine where things are in relation to the earth\'s surface, and can be represented either in a textual structured way (geographic address) or as a geometry referred to a spatial reference system (geographic location).  ### Resources - GeographicSite - Hub  ### Operations Geographic Site API performs the following operations : - Retrieve a geographic site or a collection of geographic sites - Create a new site - Update a geographic site - Delete a geographic site - Notify events on geographic site  Copyright © TM Forum 2021. All Rights Reserved  
 *
 * The version of the OpenAPI document: 5.0.0
 * 
 *
 * 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, HttpParameterCodec, HttpContext 
        }       from '@angular/common/http';
import { CustomHttpParameterCodec }                          from '../encoder';
import { Observable }                                        from 'rxjs';
import { BaseService } from '../base-service';
// @ts-ignore
import { GeographicSite } from '../model/geographicSite';
// @ts-ignore
import { GeographicSiteCreate } from '../model/geographicSiteCreate';
// @ts-ignore
import { GeographicSiteUpdate } from '../model/geographicSiteUpdate';
// @ts-ignore
import { JsonPatch } from '../model/jsonPatch';
// @ts-ignore
import { PatchGeographicSite200Response } from '../model/patchGeographicSite200Response';

// @ts-ignore
import { BASE_PATH, COLLECTION_FORMATS }                     from '../variables';
import { ApiConfiguration }                                     from '../api-configuration';



@Injectable({
  providedIn: 'root'
})
export class GeographicSiteService {

    protected basePath = 'https://serverRoot';
    public defaultHeaders = new HttpHeaders();
    public configuration = new ApiConfiguration();
    public encoder: HttpParameterCodec;

    constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string|string[], @Optional() configuration: ApiConfiguration) {
        if (configuration) {
            this.configuration = configuration;
        }
        if (typeof this.configuration.rootUrl !== 'string') {
            if (Array.isArray(basePath) && basePath.length > 0) {
                basePath = basePath[0];
            }

            if (typeof basePath !== 'string') {
                basePath = this.basePath;
            }
            this.configuration.rootUrl = basePath;
        }
        this.encoder =  new CustomHttpParameterCodec();
    }


    // @ts-ignore
    private addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams {
        if (typeof value === "object" && value instanceof Date === false) {
            httpParams = this.addToHttpParamsRecursive(httpParams, value);
        } else {
            httpParams = this.addToHttpParamsRecursive(httpParams, value, key);
        }
        return httpParams;
    }

    private addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams {
        if (value == null) {
            return httpParams;
        }

        if (typeof value === "object") {
            if (Array.isArray(value)) {
                (value as any[]).forEach( elem => httpParams = this.addToHttpParamsRecursive(httpParams, elem, key));
            } else if (value instanceof Date) {
                if (key != null) {
                    httpParams = httpParams.append(key, (value as Date).toISOString().substring(0, 10));
                } else {
                   throw Error("key may not be null if value is Date");
                }
            } else {
                Object.keys(value).forEach( k => httpParams = this.addToHttpParamsRecursive(
                    httpParams, value[k], key != null ? `${key}.${k}` : k));
            }
        } else if (key != null) {
            httpParams = httpParams.append(key, value);
        } else {
            throw Error("key may not be null if value is not object or array");
        }
        return httpParams;
    }

    /**
     * Creates a GeographicSite
     * This operation creates a GeographicSite entity.
     * @param geographicSiteCreate The GeographicSite to be created
     * @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.
     */
    public createGeographicSite(geographicSiteCreate: GeographicSiteCreate, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<GeographicSite>;
    public createGeographicSite(geographicSiteCreate: GeographicSiteCreate, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpResponse<GeographicSite>>;
    public createGeographicSite(geographicSiteCreate: GeographicSiteCreate, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpEvent<GeographicSite>>;
    public createGeographicSite(geographicSiteCreate: GeographicSiteCreate, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<any> {
        if (geographicSiteCreate === null || geographicSiteCreate === undefined) {
            throw new Error('Required parameter geographicSiteCreate was null or undefined when calling createGeographicSite.');
        }

        let localVarHeaders = this.defaultHeaders;

        let localVarHttpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept;
        if (localVarHttpHeaderAcceptSelected === undefined) {
            // to determine the Accept header
            const httpHeaderAccepts: string[] = [
                'application/json'
            ];
            // localVarHttpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts);
        }
        if (localVarHttpHeaderAcceptSelected !== undefined) {
            localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected);
        }

        let localVarHttpContext: HttpContext | undefined = options && options.context;
        if (localVarHttpContext === undefined) {
            localVarHttpContext = new HttpContext();
        }

        // let localVarTransferCache: boolean | undefined = options && options.transferCache;
        // if (localVarTransferCache === undefined) {
        //     localVarTransferCache = true;
        // }


        // to determine the Content-Type header
        const consumes: string[] = [
            'application/json'
        ];
        const httpContentTypeSelected: string | undefined = 'application/json';
        if (httpContentTypeSelected !== undefined) {
            localVarHeaders = localVarHeaders.set('Content-Type', httpContentTypeSelected);
        }

        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 = `/geographicSiteManagement/v5/geographicSite`;
        return this.httpClient.request<GeographicSite>('post', `${this.configuration.rootUrl}${localVarPath}`,
            {
                context: localVarHttpContext,
                body: geographicSiteCreate,
                responseType: <any>responseType_,
                // withCredentials: this.configuration.withCredentials,
                headers: localVarHeaders,
                observe: observe,
                // transferCache: localVarTransferCache,
                reportProgress: reportProgress
            }
        );
    }

    /**
     * Deletes a GeographicSite
     * This operation deletes a GeographicSite entity.
     * @param id Identifier of the Service
     * @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.
     */
    public deleteGeographicSite(id: string, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<any>;
    public deleteGeographicSite(id: string, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpResponse<any>>;
    public deleteGeographicSite(id: string, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpEvent<any>>;
    public deleteGeographicSite(id: string, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<any> {
        if (id === null || id === undefined) {
            throw new Error('Required parameter id was null or undefined when calling deleteGeographicSite.');
        }

        let localVarHeaders = this.defaultHeaders;

        let localVarHttpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept;
        if (localVarHttpHeaderAcceptSelected === undefined) {
            // to determine the Accept header
            const httpHeaderAccepts: string[] = [
                'application/json'
            ];
            localVarHttpHeaderAcceptSelected = 'application/json';
        }
        if (localVarHttpHeaderAcceptSelected !== undefined) {
            localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected);
        }

        let localVarHttpContext: HttpContext | undefined = options && options.context;
        if (localVarHttpContext === undefined) {
            localVarHttpContext = new HttpContext();
        }

        // let localVarTransferCache: boolean | undefined = options && options.transferCache;
        // if (localVarTransferCache === undefined) {
        //     localVarTransferCache = 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 = `/geographicSiteManagement/v5/geographicSite/${this.encoder.encodeValue(id)}`;
        return this.httpClient.request<any>('delete', `${this.configuration.rootUrl}${localVarPath}`,
            {
                context: localVarHttpContext,
                responseType: <any>responseType_,
                // withCredentials: this.configuration.withCredentials,
                headers: localVarHeaders,
                observe: observe,
                // transferCache: localVarTransferCache,
                reportProgress: reportProgress
            }
        );
    }

    /**
     * List or find GeographicSite objects
     * This operation retrieves a GeographicSite entity. Attribute selection enabled for all first level attributes.
     * @param fields Comma-separated properties to be provided in response
     * @param offset Requested index for start of resources to be provided in response
     * @param limit Requested number of resources to be provided in response
     * @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.
     */
    public listGeographicSite(fields?: string, offset?: number, limit?: number, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<Array<GeographicSite>>;
    public listGeographicSite(fields?: string, offset?: number, limit?: number, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpResponse<Array<GeographicSite>>>;
    public listGeographicSite(fields?: string, offset?: number, limit?: number, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpEvent<Array<GeographicSite>>>;
    public listGeographicSite(fields?: string, offset?: number, limit?: number, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<any> {

        let localVarQueryParameters = new HttpParams({encoder: this.encoder});
        if (fields !== undefined && fields !== null) {
          localVarQueryParameters = this.addToHttpParams(localVarQueryParameters,
            <any>fields, 'fields');
        }
        if (offset !== undefined && offset !== null) {
          localVarQueryParameters = this.addToHttpParams(localVarQueryParameters,
            <any>offset, 'offset');
        }
        if (limit !== undefined && limit !== null) {
          localVarQueryParameters = this.addToHttpParams(localVarQueryParameters,
            <any>limit, 'limit');
        }

        let localVarHeaders = this.defaultHeaders;

        let localVarHttpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept;
        if (localVarHttpHeaderAcceptSelected === undefined) {
            // to determine the Accept header
            const httpHeaderAccepts: string[] = [
                'application/json'
            ];
            localVarHttpHeaderAcceptSelected = 'application/json';
        }
        if (localVarHttpHeaderAcceptSelected !== undefined) {
            localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected);
        }

        let localVarHttpContext: HttpContext | undefined = options && options.context;
        if (localVarHttpContext === undefined) {
            localVarHttpContext = new HttpContext();
        }

        // let localVarTransferCache: boolean | undefined = options && options.transferCache;
        // if (localVarTransferCache === undefined) {
        //     localVarTransferCache = 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 = `/geographicSiteManagement/v5/geographicSite`;
        return this.httpClient.request<Array<GeographicSite>>('get', `${this.configuration.rootUrl}${localVarPath}`,
            {
                context: localVarHttpContext,
                params: localVarQueryParameters,
                responseType: <any>responseType_,
                // withCredentials: this.configuration.withCredentials,
                headers: localVarHeaders,
                observe: observe,
                // transferCache: localVarTransferCache,
                reportProgress: reportProgress
            }
        );
    }

    /**
     * Updates partially a GeographicSite
     * This operation updates partially a GeographicSite entity.
     * @param id Identifier of the Service
     * @param geographicSiteUpdate The GeographicSite to be patched
     * @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.
     */
    public patchGeographicSite(id: string, geographicSiteUpdate: GeographicSiteUpdate, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json' | 'application/merge-patch+json' | 'application/json-patch+json' | 'application/json-patch-query+json', context?: HttpContext}): Observable<GeographicSite>;
    public patchGeographicSite(id: string, geographicSiteUpdate: GeographicSiteUpdate, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json' | 'application/merge-patch+json' | 'application/json-patch+json' | 'application/json-patch-query+json', context?: HttpContext}): Observable<HttpResponse<GeographicSite>>;
    public patchGeographicSite(id: string, geographicSiteUpdate: GeographicSiteUpdate, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json' | 'application/merge-patch+json' | 'application/json-patch+json' | 'application/json-patch-query+json', context?: HttpContext}): Observable<HttpEvent<GeographicSite>>;
    public patchGeographicSite(id: string, geographicSiteUpdate: GeographicSiteUpdate, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json' | 'application/merge-patch+json' | 'application/json-patch+json' | 'application/json-patch-query+json', context?: HttpContext}): Observable<any> {
        if (id === null || id === undefined) {
            throw new Error('Required parameter id was null or undefined when calling patchGeographicSite.');
        }
        if (geographicSiteUpdate === null || geographicSiteUpdate === undefined) {
            throw new Error('Required parameter geographicSiteUpdate was null or undefined when calling patchGeographicSite.');
        }

        let localVarHeaders = this.defaultHeaders;

        let localVarHttpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept;
        if (localVarHttpHeaderAcceptSelected === undefined) {
            // to determine the Accept header
            const httpHeaderAccepts: string[] = [
                'application/json',
                'application/merge-patch+json',
                'application/json-patch+json',
                'application/json-patch-query+json'
            ];
            localVarHttpHeaderAcceptSelected = 'application/json';
        }
        if (localVarHttpHeaderAcceptSelected !== undefined) {
            localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected);
        }

        let localVarHttpContext: HttpContext | undefined = options && options.context;
        if (localVarHttpContext === undefined) {
            localVarHttpContext = new HttpContext();
        }

        // let localVarTransferCache: boolean | undefined = options && options.transferCache;
        // if (localVarTransferCache === undefined) {
        //     localVarTransferCache = true;
        // }


        // to determine the Content-Type header
        const consumes: string[] = [
            'application/json',
            'application/merge-patch+json',
            'application/json-patch+json',
            'application/json-patch-query+json'
        ];
        const httpContentTypeSelected: string | undefined = 'application/json';
        if (httpContentTypeSelected !== undefined) {
            localVarHeaders = localVarHeaders.set('Content-Type', httpContentTypeSelected);
        }

        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 = `/geographicSiteManagement/v5/geographicSite/${this.encoder.encodeValue(id)}`;
        return this.httpClient.request<GeographicSite>('patch', `${this.configuration.rootUrl}${localVarPath}`,
            {
                context: localVarHttpContext,
                body: geographicSiteUpdate,
                responseType: <any>responseType_,
                // withCredentials: this.configuration.withCredentials,
                headers: localVarHeaders,
                observe: observe,
                reportProgress: reportProgress
            }
        );
    }

    /**
     * Retrieves a GeographicSite by ID
     * List or find GeographicSite objects
     * @param id Identifier of the Service
     * @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.
     */
    public retrieveGeographicSite(id: string, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<GeographicSite>;
    public retrieveGeographicSite(id: string, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpResponse<GeographicSite>>;
    public retrieveGeographicSite(id: string, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpEvent<GeographicSite>>;
    public retrieveGeographicSite(id: string, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<any> {
        if (id === null || id === undefined) {
            throw new Error('Required parameter id was null or undefined when calling retrieveGeographicSite.');
        }

        let localVarHeaders = this.defaultHeaders;

        let localVarHttpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept;
        if (localVarHttpHeaderAcceptSelected === undefined) {
            // to determine the Accept header
            const httpHeaderAccepts: string[] = [
                'application/json'
            ];
            localVarHttpHeaderAcceptSelected = 'application/json';
        }
        if (localVarHttpHeaderAcceptSelected !== undefined) {
            localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected);
        }

        let localVarHttpContext: HttpContext | undefined = options && options.context;
        if (localVarHttpContext === undefined) {
            localVarHttpContext = new HttpContext();
        }


        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 = `/geographicSiteManagement/v5/geographicSite/${this.encoder.encodeValue(id)}`;
        return this.httpClient.request<GeographicSite>('get', `${this.configuration.rootUrl}${localVarPath}`,
            {
                context: localVarHttpContext,
                responseType: <any>responseType_,
                // withCredentials: this.configuration.withCredentials,
                headers: localVarHeaders,
                observe: observe,
                reportProgress: reportProgress
            }
        );
    }

}
