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

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

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

  toggleErrorMsg = new EventEmitter()

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

  /**
  * Gets Supplier Main Settings
  * @returns {object} promise
  */
  getSupplierMainSettings() {
    return this.api.read('/Supplier-MainSettings');
  };

  /**
  * Gets credit terms dropdown information 
  * @returns {object} promise
  */
  getCreditTermsInfo() {
    return this.api.read('/Supplier-MainSettings/getCreditTermsInfo');
  };

  /**
  * Gets payment types dropdown information 
  * @returns {object} promise
  */
  getPaymentTypesInfo() {
    return this.api.read('/Supplier-MainSettings/getPaymentTypesInfo');
  };

  /**
  * Gets classifications dropdown information 
  * @returns {object} promise
  */
  getClassificationsInfo() {
    return this.api.read('/Supplier-MainSettings/getClassificationsInfo');
  };

  /**
   * Gets Active Authorized Distributor of Record List
   * @returns {object} promise
  */
  getActiveADR() {
    return this.api.read('/Supplier-MainSettings/getActiveADR');
  };

  /**
   * Remove Authorized Distributor of Record labeler code
   * @returns {object} promise
  */
  removeADR(labeler_code: string) {
    return this.api.read('/Supplier-MainSettings/removeADR?labeler_code=' + labeler_code);
  };

  /**
   * Update Supplier Main Settings
   * @returns {object} promise
  */
  saveMainSettings(data: any) {
    return this.api.create('/Supplier-MainSettings', data);
  };

  /**
   * Gets classification business types
   * @returns {object} promise
  */
  getBusinessTypes(clsId: number | string) {
    return this.api.read('/Supplier-MainSettings/getClsBusinessTypes?clsId=' + clsId);
  };

  /**
   * for TRX-6493
   * Gets supplier schedule control products list
   * @returns array
  */
  getScheduleControlList() {
    return this.api.read('/Supplier-MainSettings/getManagedSchedInfo');
  };

  /**
  * for TRX-6493
  * Delete Auction
  * @param {type} id
  * @returns {unresolved}
  */
  deleteManageControlProduct(ndc: string) {
    return this.api.read('/Supplier-MainSettings/removeManagedSched?ndc=' + ndc);
  };

  /**
   * Call back error method for manage supplier service
   */
  errorCallBack(response: any) {
    this.api.errorCallback(response);
  };

  /**
   * Get shipping carriers list.
   * @returns {unresolved}
   */
  getCarriers() {
    return this.api.read('/Supplier-MainSettings/getCarriers');
  };

  getManufacturers(labelerCode: string) {
    return this.api.read('/Supplier-MainSettings/getManufacturers?labelerCode=' + labelerCode);
  }

}
