/**
 * 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 {ApplicantDetailDto} from '../model/applicantDetailDto';
import {ApplicantUpdateDto} from '../model/applicantUpdateDto';
import {ExperienceDto} from '../model/experienceDto';
import {PageApplicantDto} from '../model/pageApplicantDto';

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

@Injectable()
export class ApplicantService {

  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 experience
   *
   * @param body
   * @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 addExperience(body: ExperienceDto, applicantId: string, observe?: 'body', reportProgress?: boolean): Observable<ApplicantDetailDto>;
  public addExperience(body: ExperienceDto, applicantId: string, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<ApplicantDetailDto>>;
  public addExperience(body: ExperienceDto, applicantId: string, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<ApplicantDetailDto>>;
  public addExperience(body: ExperienceDto, applicantId: 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 addExperience.');
    }

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

    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<ApplicantDetailDto>('post', `${this.basePath}/applicants/${encodeURIComponent(String(applicantId))}/experience`,
      {
        body: body,
        withCredentials: this.configuration.withCredentials,
        headers: headers,
        observe: observe,
        reportProgress: reportProgress
      }
    );
  }

  /**
   * Generates CV for given applicant
   *
   * @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 generateCV(applicantId: string, observe?: 'body', reportProgress?: boolean): Observable<Blob>;
  public generateCV(applicantId: string, observe: any = 'body', reportProgress: boolean = false): Observable<Blob> {

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

    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/pdf'
    ];
    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('get', `${this.basePath}/applicants/${encodeURIComponent(String(applicantId))}/generate-cv`,
      {
        withCredentials: this.configuration.withCredentials,
        headers: headers,
        observe: observe,
        reportProgress: reportProgress,
        responseType: "blob"
      }
    );
  }

  /**
   * Returns an applicant by given id
   *
   * @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 getApplicant(applicantId: string, observe?: 'body', reportProgress?: boolean): Observable<ApplicantDetailDto>;
  public getApplicant(applicantId: string, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<ApplicantDetailDto>>;
  public getApplicant(applicantId: string, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<ApplicantDetailDto>>;
  public getApplicant(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 getApplicant.');
    }

    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<ApplicantDetailDto>('get', `${this.basePath}/applicants/${encodeURIComponent(String(applicantId))}`,
      {
        withCredentials: this.configuration.withCredentials,
        headers: headers,
        observe: observe,
        reportProgress: reportProgress
      }
    );
  }

  /**
   * Returns all applicants
   *
   * @param q
   * @param jobPosition
   * @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 getApplicants(q?: Array<string>, jobPosition?: string, page?: number, size?: number, sort?: Array<string>, observe?: 'body', reportProgress?: boolean): Observable<PageApplicantDto>;
  public getApplicants(q?: Array<string>, jobPosition?: string, page?: number, size?: number, sort?: Array<string>, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<PageApplicantDto>>;
  public getApplicants(q?: Array<string>, jobPosition?: string, page?: number, size?: number, sort?: Array<string>, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<PageApplicantDto>>;
  public getApplicants(q?: Array<string>, jobPosition?: 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 (jobPosition !== undefined && jobPosition !== null) {
      queryParameters = queryParameters.set('jobPosition', <any>jobPosition);
    }
    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;

    // 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<PageApplicantDto>('get', `${this.basePath}/applicants`,
      {
        params: queryParameters,
        withCredentials: this.configuration.withCredentials,
        headers: headers,
        observe: observe,
        reportProgress: reportProgress
      }
    );
  }

  /**
   * Delete experience
   *
   * @param applicantId
   * @param experienceId
   * @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 removeExperience(applicantId: string, experienceId: string, observe?: 'body', reportProgress?: boolean): Observable<ApplicantDetailDto>;
  public removeExperience(applicantId: string, experienceId: string, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<ApplicantDetailDto>>;
  public removeExperience(applicantId: string, experienceId: string, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<ApplicantDetailDto>>;
  public removeExperience(applicantId: string, experienceId: 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 removeExperience.');
    }

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

    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<ApplicantDetailDto>('delete', `${this.basePath}/applicants/${encodeURIComponent(String(applicantId))}/experience/${encodeURIComponent(String(experienceId))}`,
      {
        withCredentials: this.configuration.withCredentials,
        headers: headers,
        observe: observe,
        reportProgress: reportProgress
      }
    );
  }

  /**
   * Updates an applicant by given id
   *
   * @param body
   * @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 updateApplicant(body: ApplicantUpdateDto, applicantId: string, observe?: 'body', reportProgress?: boolean): Observable<ApplicantDetailDto>;
  public updateApplicant(body: ApplicantUpdateDto, applicantId: string, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<ApplicantDetailDto>>;
  public updateApplicant(body: ApplicantUpdateDto, applicantId: string, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<ApplicantDetailDto>>;
  public updateApplicant(body: ApplicantUpdateDto, applicantId: 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 updateApplicant.');
    }

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

    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<ApplicantDetailDto>('put', `${this.basePath}/applicants/${encodeURIComponent(String(applicantId))}`,
      {
        body: body,
        withCredentials: this.configuration.withCredentials,
        headers: headers,
        observe: observe,
        reportProgress: reportProgress
      }
    );
  }

}
