/**
 * job-portal
 * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
 *
 * OpenAPI spec version: local
 *
 *
 * NOTE: This class is auto generated by the swagger code generator program.
 * https://github.com/swagger-api/swagger-codegen.git
 * Do not edit the class manually.
 *//* tslint:disable:no-unused-variable member-ordering */

import {Inject, Injectable, Optional} from '@angular/core';
import {HttpClient, HttpEvent, HttpHeaders, HttpParams, HttpResponse} from '@angular/common/http';
import {CustomHttpUrlEncodingCodec} from '../encoder';

import {Observable} from 'rxjs';

import {FavouritesJobsResponse} from '../model/favouritesJobsResponse';
import {JobPositionCreateDto} from '../model/jobPositionCreateDto';
import {JobPositionDetailDto} from '../model/jobPositionDetailDto';
import {JobPositionUpdateDto} from '../model/jobPositionUpdateDto';
import {PageJobPositionDto} from '../model/pageJobPositionDto';

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


@Injectable()
export class JobPositionService {

  protected basePath = 'http://localhost:8080';
    public defaultHeaders = new HttpHeaders();
    public configuration = new Configuration();

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

    /**
     * @param consumes string[] mime-types
     * @return true: consumes contains 'multipart/form-data', false: otherwise
     */
    private canConsumeForm(consumes: string[]): boolean {
        const form = 'multipart/form-data';
        for (const consume of consumes) {
            if (form === consume) {
                return true;
            }
        }
        return false;
    }


    /**
     * Add to favorite jobs of a current user
     *
     * @param applicantId
     * @param jobPositionId
     * @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 addToFavorites(applicantId: string, jobPositionId: string, observe?: 'body', reportProgress?: boolean): Observable<FavouritesJobsResponse>;
    public addToFavorites(applicantId: string, jobPositionId: string, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<FavouritesJobsResponse>>;
    public addToFavorites(applicantId: string, jobPositionId: string, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<FavouritesJobsResponse>>;
    public addToFavorites(applicantId: string, jobPositionId: string, observe: any = 'body', reportProgress: boolean = false ): Observable<any> {

        if (applicantId === null || applicantId === undefined) {
            throw new Error('Required parameter applicantId was null or undefined when calling addToFavorites.');
        }

        if (jobPositionId === null || jobPositionId === undefined) {
            throw new Error('Required parameter jobPositionId was null or undefined when calling addToFavorites.');
        }

        let headers = this.defaultHeaders;

        // authentication (auth_schema) required
        if (this.configuration.accessToken) {
            const accessToken = typeof this.configuration.accessToken === 'function'
                ? this.configuration.accessToken()
                : this.configuration.accessToken;
            headers = headers.set('Authorization', 'Bearer ' + accessToken);
        }
        // to determine the Accept header
        let httpHeaderAccepts: string[] = [
            'application/json'
        ];
        const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
        if (httpHeaderAcceptSelected != undefined) {
            headers = headers.set('Accept', httpHeaderAcceptSelected);
        }

        // to determine the Content-Type header
        const consumes: string[] = [
        ];

        return this.httpClient.request<FavouritesJobsResponse>('put',`${this.basePath}/positions/applicants/${encodeURIComponent(String(applicantId))}/favourites/${encodeURIComponent(String(jobPositionId))}/add`,
            {
                withCredentials: this.configuration.withCredentials,
                headers: headers,
                observe: observe,
                reportProgress: reportProgress
            }
        );
    }

    /**
     * Apply for a job position
     *
     * @param applicantId
     * @param jobPositionId
     * @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 apply(applicantId: string, jobPositionId: string, observe?: 'body', reportProgress?: boolean): Observable<JobPositionDetailDto>;
    public apply(applicantId: string, jobPositionId: string, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<JobPositionDetailDto>>;
    public apply(applicantId: string, jobPositionId: string, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<JobPositionDetailDto>>;
    public apply(applicantId: string, jobPositionId: string, observe: any = 'body', reportProgress: boolean = false ): Observable<any> {

        if (applicantId === null || applicantId === undefined) {
            throw new Error('Required parameter applicantId was null or undefined when calling apply.');
        }

        if (jobPositionId === null || jobPositionId === undefined) {
            throw new Error('Required parameter jobPositionId was null or undefined when calling apply.');
        }

        let headers = this.defaultHeaders;

        // authentication (auth_schema) required
        if (this.configuration.accessToken) {
            const accessToken = typeof this.configuration.accessToken === 'function'
                ? this.configuration.accessToken()
                : this.configuration.accessToken;
            headers = headers.set('Authorization', 'Bearer ' + accessToken);
        }
        // to determine the Accept header
        let httpHeaderAccepts: string[] = [
            'application/json'
        ];
        const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
        if (httpHeaderAcceptSelected != undefined) {
            headers = headers.set('Accept', httpHeaderAcceptSelected);
        }

        // to determine the Content-Type header
        const consumes: string[] = [
        ];

        return this.httpClient.request<JobPositionDetailDto>('post',`${this.basePath}/positions/applicants/${encodeURIComponent(String(applicantId))}/apply/${encodeURIComponent(String(jobPositionId))}`,
            {
                withCredentials: this.configuration.withCredentials,
                headers: headers,
                observe: observe,
                reportProgress: reportProgress
            }
        );
    }

    /**
     * Create a job position
     *
     * @param body
     * @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 createJobPosition(body: JobPositionCreateDto, observe?: 'body', reportProgress?: boolean): Observable<JobPositionDetailDto>;
    public createJobPosition(body: JobPositionCreateDto, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<JobPositionDetailDto>>;
    public createJobPosition(body: JobPositionCreateDto, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<JobPositionDetailDto>>;
    public createJobPosition(body: JobPositionCreateDto, observe: any = 'body', reportProgress: boolean = false ): Observable<any> {

        if (body === null || body === undefined) {
            throw new Error('Required parameter body was null or undefined when calling createJobPosition.');
        }

        let headers = this.defaultHeaders;

        // authentication (auth_schema) required
        if (this.configuration.accessToken) {
            const accessToken = typeof this.configuration.accessToken === 'function'
                ? this.configuration.accessToken()
                : this.configuration.accessToken;
            headers = headers.set('Authorization', 'Bearer ' + accessToken);
        }
        // to determine the Accept header
        let httpHeaderAccepts: string[] = [
            'application/json'
        ];
        const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
        if (httpHeaderAcceptSelected != undefined) {
            headers = headers.set('Accept', httpHeaderAcceptSelected);
        }

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

        return this.httpClient.request<JobPositionDetailDto>('post',`${this.basePath}/positions`,
            {
                body: body,
                withCredentials: this.configuration.withCredentials,
                headers: headers,
                observe: observe,
                reportProgress: reportProgress
            }
        );
    }

    /**
     * Get favorite jobs of a current user
     *
     * @param applicantId
     * @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 getFavorites(applicantId: string, observe?: 'body', reportProgress?: boolean): Observable<FavouritesJobsResponse>;
    public getFavorites(applicantId: string, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<FavouritesJobsResponse>>;
    public getFavorites(applicantId: string, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<FavouritesJobsResponse>>;
    public getFavorites(applicantId: string, observe: any = 'body', reportProgress: boolean = false ): Observable<any> {

        if (applicantId === null || applicantId === undefined) {
            throw new Error('Required parameter applicantId was null or undefined when calling getFavorites.');
        }

        let headers = this.defaultHeaders;

        // authentication (auth_schema) required
        if (this.configuration.accessToken) {
            const accessToken = typeof this.configuration.accessToken === 'function'
                ? this.configuration.accessToken()
                : this.configuration.accessToken;
            headers = headers.set('Authorization', 'Bearer ' + accessToken);
        }
        // to determine the Accept header
        let httpHeaderAccepts: string[] = [
            'application/json'
        ];
        const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
        if (httpHeaderAcceptSelected != undefined) {
            headers = headers.set('Accept', httpHeaderAcceptSelected);
        }

        // to determine the Content-Type header
        const consumes: string[] = [
        ];

        return this.httpClient.request<FavouritesJobsResponse>('get',`${this.basePath}/positions/applicants/${encodeURIComponent(String(applicantId))}/favorites`,
            {
                withCredentials: this.configuration.withCredentials,
                headers: headers,
                observe: observe,
                reportProgress: reportProgress
            }
        );
    }

    /**
     * Returns a job position by given id
     *
     * @param jobPositionId
     * @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 getJobPosition(jobPositionId: string, observe?: 'body', reportProgress?: boolean): Observable<JobPositionDetailDto>;
    public getJobPosition(jobPositionId: string, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<JobPositionDetailDto>>;
    public getJobPosition(jobPositionId: string, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<JobPositionDetailDto>>;
    public getJobPosition(jobPositionId: string, observe: any = 'body', reportProgress: boolean = false ): Observable<any> {

        if (jobPositionId === null || jobPositionId === undefined) {
            throw new Error('Required parameter jobPositionId was null or undefined when calling getJobPosition.');
        }

        let headers = this.defaultHeaders;

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

        // to determine the Content-Type header
        const consumes: string[] = [
        ];

        return this.httpClient.request<JobPositionDetailDto>('get',`${this.basePath}/positions/${encodeURIComponent(String(jobPositionId))}`,
            {
                withCredentials: this.configuration.withCredentials,
                headers: headers,
                observe: observe,
                reportProgress: reportProgress
            }
        );
    }

    /**
     * Returns all job positions
     *
     * @param q
     * @param status
     * @param categories
     * @param companies
     * @param page Zero-based page index (0..N)
     * @param size The size of the page to be returned
     * @param sort Sorting criteria in the format: property,(asc|desc). Default sort order is ascending. Multiple sort criteria are supported.
     * @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 getJobPositions(q?: Array<string>, status?: string, categories?: Array<string>, companies?: Array<string>, page?: number, size?: number, sort?: Array<string>, observe?: 'body', reportProgress?: boolean): Observable<PageJobPositionDto>;
    public getJobPositions(q?: Array<string>, status?: string, categories?: Array<string>, companies?: Array<string>, page?: number, size?: number, sort?: Array<string>, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<PageJobPositionDto>>;
    public getJobPositions(q?: Array<string>, status?: string, categories?: Array<string>, companies?: Array<string>, page?: number, size?: number, sort?: Array<string>, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<PageJobPositionDto>>;
    public getJobPositions(q?: Array<string>, status?: string, categories?: Array<string>, companies?: Array<string>, page?: number, size?: number, sort?: Array<string>, observe: any = 'body', reportProgress: boolean = false ): Observable<any> {








        let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()});
        if (q) {
            q.forEach((element) => {
                queryParameters = queryParameters.append('q', <any>element);
            })
        }
        if (status !== undefined && status !== null) {
            queryParameters = queryParameters.set('status', <any>status);
        }
        if (categories) {
            categories.forEach((element) => {
                queryParameters = queryParameters.append('categories', <any>element);
            })
        }
        if (companies) {
            companies.forEach((element) => {
                queryParameters = queryParameters.append('companies', <any>element);
            })
        }
        if (page !== undefined && page !== null) {
            queryParameters = queryParameters.set('page', <any>page);
        }
        if (size !== undefined && size !== null) {
            queryParameters = queryParameters.set('size', <any>size);
        }
        if (sort) {
            sort.forEach((element) => {
                queryParameters = queryParameters.append('sort', <any>element);
            })
        }

        let headers = this.defaultHeaders;

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

        // to determine the Content-Type header
        const consumes: string[] = [
        ];

        return this.httpClient.request<PageJobPositionDto>('get',`${this.basePath}/positions`,
            {
                params: queryParameters,
                withCredentials: this.configuration.withCredentials,
                headers: headers,
                observe: observe,
                reportProgress: reportProgress
            }
        );
    }

    /**
     * Remove from favorite jobs of a current user
     *
     * @param applicantId
     * @param jobPositionId
     * @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 removeFromFavorites(applicantId: string, jobPositionId: string, observe?: 'body', reportProgress?: boolean): Observable<FavouritesJobsResponse>;
    public removeFromFavorites(applicantId: string, jobPositionId: string, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<FavouritesJobsResponse>>;
    public removeFromFavorites(applicantId: string, jobPositionId: string, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<FavouritesJobsResponse>>;
    public removeFromFavorites(applicantId: string, jobPositionId: string, observe: any = 'body', reportProgress: boolean = false ): Observable<any> {

        if (applicantId === null || applicantId === undefined) {
            throw new Error('Required parameter applicantId was null or undefined when calling removeFromFavorites.');
        }

        if (jobPositionId === null || jobPositionId === undefined) {
            throw new Error('Required parameter jobPositionId was null or undefined when calling removeFromFavorites.');
        }

        let headers = this.defaultHeaders;

        // authentication (auth_schema) required
        if (this.configuration.accessToken) {
            const accessToken = typeof this.configuration.accessToken === 'function'
                ? this.configuration.accessToken()
                : this.configuration.accessToken;
            headers = headers.set('Authorization', 'Bearer ' + accessToken);
        }
        // to determine the Accept header
        let httpHeaderAccepts: string[] = [
            'application/json'
        ];
        const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
        if (httpHeaderAcceptSelected != undefined) {
            headers = headers.set('Accept', httpHeaderAcceptSelected);
        }

        // to determine the Content-Type header
        const consumes: string[] = [
        ];

        return this.httpClient.request<FavouritesJobsResponse>('put',`${this.basePath}/positions/applicants/${encodeURIComponent(String(applicantId))}/favourites/${encodeURIComponent(String(jobPositionId))}/remove`,
            {
                withCredentials: this.configuration.withCredentials,
                headers: headers,
                observe: observe,
                reportProgress: reportProgress
            }
        );
    }

    /**
     * Change a state of a job position
     *
     * @param body
     * @param jobPositionId
     * @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 updateJobPosition(body: JobPositionUpdateDto, jobPositionId: string, observe?: 'body', reportProgress?: boolean): Observable<JobPositionDetailDto>;
    public updateJobPosition(body: JobPositionUpdateDto, jobPositionId: string, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<JobPositionDetailDto>>;
    public updateJobPosition(body: JobPositionUpdateDto, jobPositionId: string, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<JobPositionDetailDto>>;
    public updateJobPosition(body: JobPositionUpdateDto, jobPositionId: string, observe: any = 'body', reportProgress: boolean = false ): Observable<any> {

        if (body === null || body === undefined) {
            throw new Error('Required parameter body was null or undefined when calling updateJobPosition.');
        }

        if (jobPositionId === null || jobPositionId === undefined) {
            throw new Error('Required parameter jobPositionId was null or undefined when calling updateJobPosition.');
        }

        let headers = this.defaultHeaders;

        // authentication (auth_schema) required
        if (this.configuration.accessToken) {
            const accessToken = typeof this.configuration.accessToken === 'function'
                ? this.configuration.accessToken()
                : this.configuration.accessToken;
            headers = headers.set('Authorization', 'Bearer ' + accessToken);
        }
        // to determine the Accept header
        let httpHeaderAccepts: string[] = [
            'application/json'
        ];
        const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
        if (httpHeaderAcceptSelected != undefined) {
            headers = headers.set('Accept', httpHeaderAcceptSelected);
        }

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

        return this.httpClient.request<JobPositionDetailDto>('put',`${this.basePath}/positions/${encodeURIComponent(String(jobPositionId))}`,
            {
                body: body,
                withCredentials: this.configuration.withCredentials,
                headers: headers,
                observe: observe,
                reportProgress: reportProgress
            }
        );
    }

}
