// Angular Core
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

// Services
import { ApiService } from '../api/api.service';

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

  constructor(private http: HttpClient, public api: ApiService) { }

  /**
   * Gets content for static pages
   * @return {unresolved}
   */
  getContent(pageHandle: string) {
    return this.api.read('/Content?id=' + pageHandle);
  };

  /**
   * Method to get Banner Ads
   * @return {unresolved}
   */
  bannerAd(adSectionId: number, adLimit: number, ndc: string = '', pageName: string = '') {
    var data = {
      adSectionId: adSectionId,
      adLimit: adLimit,
      ndc: ndc,
      pageName: pageName
    };
    return this.api.create('/User-Ad', data);
  };
  /**
   * Method to send clicks on Banner Ads
   * @return {unresolved}
   */
  bannerAdClick(adId: number) {
    var data = {
      advertId: adId,
      type: 'click'
    };
    return this.api.create('/User-Ad', data)
      .subscribe();
  }

  /**
   * Gets content for Google Analytics Registration Code
   * @return {unresolved}
   */
  getGoogleAnalyticsCode() {
    return this.api.read('/GeneralSettingsData/getGoogleAnalyticsCode');
  };
  /**
   * Handles error with ajax API
   * @param {object} response
   * @returns {undefined}
   */
  errorCallBack(response: any) {
    this.api.errorCallback(response);
  };
}
