/**
 * GNUBoat Mapservice API
 * API to upload log files with water depth to GNUBoat server
 *
 * The version of the OpenAPI document: v1
 * Contact: info@engsas.de
 *
 * 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 }       from '@angular/common/http';
import { CustomHttpParameterCodec }                          from '../encoder';
import { Observable }                                        from 'rxjs';

import { HttpError } from '../model/models';

import { BASE_PATH, COLLECTION_FORMATS }                     from '../variables';
import { Configuration }                                     from '../configuration';



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

    protected basePath = 'https://gnuboat.engsas.com/mapservice/v1';
    public defaultHeaders = new HttpHeaders();
    public configuration = new Configuration();
    public encoder: HttpParameterCodec;

    constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) {
        if (configuration) {
            this.configuration = configuration;
        }
        if (typeof this.configuration.basePath !== 'string') {
            if (typeof basePath !== 'string') {
                basePath = this.basePath;
            }
            this.configuration.basePath = basePath;
        }
        this.encoder = this.configuration.encoder || new CustomHttpParameterCodec();
    }



    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().substr(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;
    }

    /**
     * Represents a tile
     * Returns the map tile x_tile, y_tile at Zoomlevel zoom
     * @param accuracy Accuracy of generated tiles
     * @param resolution Resolution of the tiles
     * @param zoom Zoomlevel
     * @param xTile Number of the tile in x dimension
     * @param yTile Number of the tile in y dimension
     * @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 tilesTileGet(accuracy: 'high' | 'low', resolution: 256 | 512, zoom: number, xTile: number, yTile: number, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'image/_*' | 'application/problem+json'}): Observable<Blob>;
    public tilesTileGet(accuracy: 'high' | 'low', resolution: 256 | 512, zoom: number, xTile: number, yTile: number, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'image/_*' | 'application/problem+json'}): Observable<HttpResponse<Blob>>;
    public tilesTileGet(accuracy: 'high' | 'low', resolution: 256 | 512, zoom: number, xTile: number, yTile: number, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'image/_*' | 'application/problem+json'}): Observable<HttpEvent<Blob>>;
    public tilesTileGet(accuracy: 'high' | 'low', resolution: 256 | 512, zoom: number, xTile: number, yTile: number, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'image/_*' | 'application/problem+json'}): Observable<any> {
        if (accuracy === null || accuracy === undefined) {
            throw new Error('Required parameter accuracy was null or undefined when calling tilesTileGet.');
        }
        if (resolution === null || resolution === undefined) {
            throw new Error('Required parameter resolution was null or undefined when calling tilesTileGet.');
        }
        if (zoom === null || zoom === undefined) {
            throw new Error('Required parameter zoom was null or undefined when calling tilesTileGet.');
        }
        if (xTile === null || xTile === undefined) {
            throw new Error('Required parameter xTile was null or undefined when calling tilesTileGet.');
        }
        if (yTile === null || yTile === undefined) {
            throw new Error('Required parameter yTile was null or undefined when calling tilesTileGet.');
        }

        let headers = this.defaultHeaders;

        let httpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept;
        if (httpHeaderAcceptSelected === undefined) {
            // to determine the Accept header
            const httpHeaderAccepts: string[] = [
                'image/_*',
                'application/problem+json'
            ];
            httpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts);
        }
        if (httpHeaderAcceptSelected !== undefined) {
            headers = headers.set('Accept', httpHeaderAcceptSelected);
        }


        return this.httpClient.get(`${this.configuration.basePath}/tiles/gnuboat/${encodeURIComponent(String(accuracy))}/${encodeURIComponent(String(resolution))}/${encodeURIComponent(String(zoom))}/${encodeURIComponent(String(xTile))}/${encodeURIComponent(String(yTile))}.png`,
            {
                responseType: "blob",
                withCredentials: this.configuration.withCredentials,
                headers: headers,
                observe: observe,
                reportProgress: reportProgress
            }
        );
    }

}
