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

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

// Interfaces
import { BuyerInfoUpdateInterface } from 'src/app/interfaces/user/buyer-info-update-interface';

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

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

  /**
     * Gets Manage Buyer Data
     * @param {string} userName
     * @returns {object} promise
     */
  getBuyerData(userName: string) {
    return this.api.read('/Supplier-ManageBuyer?buyer_name=' + userName);
  };

  /**
   * Sends request to get PDF file content
   * @param {string} doc
   * @param {int} pharmacyId
   * @returns {object} promise
   */
  viewDocument(doc: string, pharmacyId: number) {
    var data = {
      document: doc,
      pharmacy_id: pharmacyId
    };
    return this.api.create('/Supplier-ManageBuyer', data);
  };
  /**
   * Sends request to save manage buyer info
   * @param {array} data
   * @returns {object} promise
   */
  saveBuyerData(data: BuyerInfoUpdateInterface) {
    return this.api.create('/Supplier-ManageBuyer', data);
  };

  /**
   * Gets Account staus list
   * @returns {object} promise
   */
  getAccountStatuses() {
    return this.api.read('/Supplier-ManageBuyer/getAccountStatuses');
  };

  /**
   * Gets Credit Terms
   * @returns {object} promise
   */
  getCreditTerms() {
    return this.api.read('/Supplier-ManageBuyer/getCreditTerms');
  };

  /**
   * Gets Payment Types
   * @returns {object} promise
   */
  getPaymentTypes() {
    return this.api.read('/Supplier-ManageBuyer/getPaymentTypes');
  };

  /**
   * Gets Payment Types
   * @param {int} userSupplierAccId
   * @returns {object} promise
   */
  getUserSpecificPaymentTypes(userSupplierAccId: number) {
    return this.api.read('/Supplier-ManageBuyer/getUserSpecificPaymentTypes?id=' + userSupplierAccId);
  };

  /**
   * Gets Control Substance Information
   * @returns {object} promise
   */
  isCSAppRequired() {
    return this.api.read('/Supplier-ManageBuyer/isCSAppRequired')
  };

  /**
   * Method introduced as part of TRX-7978
   * Gets Buyer DEA number list which are having given account number
   * @param string accNum
   * @param int buyerId
   * 
   * @returns {object} promise
  */
  getBuyersListByAccNum(accNum: string, buyerId: number) {
    return this.api.read('/Supplier-ManageBuyer/getBuyersListByAccNum?accNum=' + accNum + '&buyerId=' + buyerId);
  };

  /**
   * Call back error method for manage supplier service
   * @param {object} response object
   * @returns {undefined}
   */
  errorCallBack(response: {}) {
    this.api.errorCallback(response);
  };

}
