// 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 AuthorizedStatesService {

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

  getAuthorizedStates(type: any) {
    return this.api.read('/Supplier-AuthorizedStates?type=' + type);
  };

  /**
   * Update Supplier Authorized States and territories
   * @param {json} data
   * @returns {object} promise
  */
  saveAuthorizedStates(data: any) {
    return this.api.create('/Supplier-AuthorizedStates', data);
  };

  /**
   * Gets restricted categories
   * @returns {object} promise
  */
  getRestrictedCategories() {
    return this.api.read('/Supplier-AuthorizedStates/getRestrictedCategories');
  };

  /** 
   * Gets active restricted categories
   * @returns {object} promise
  */
  getActiveRestrictedCategories() {
    return this.api.read('/Supplier-AuthorizedStates/getActiveRestrictedCategories');
  };

  /**
   * Gets state names
   * @param {number | null} categoryId
   * @returns {object} promise
  */
  getRestrictedStates(categoryId: number | null) {
    return this.api.read('/Supplier-AuthorizedStates/getRestrictedCategoryStates?categoryId=' + categoryId);
  };

   /**
    * Method used to Removes Supplier Authorized State License Document
    * @param {json} data
    * @returns {object} promise
   */
   removeStateLicense(data: any) {
       return this.api.create('/Supplier-AuthorizedStates/removeStateLicense',data);
   };

   /**
    * Mehtod used to view Supplier Authorized State License Document
    * @param {json} data
    * @returns {object} promise
   */
   viewLicenseDocument(data: any) {
       return this.api.create('/Supplier-AuthorizedStates/viewLicenseDocument',data);
   };

   /**
    * Mehtod used to validate Supplier Authorized State License Document
    * @param {json} data
    * @returns {object} promise
   */
   validateLicenseDoc(data: any) {
       return this.api.create('/Supplier-AuthorizedStates/validateLicenseDoc',data);
   };

    /**
    * Mehtod used to validate Supplier Authorized State License Document
    * @param {json} data
    * @returns {object} promise
   */
   updateLicenseExpiration(data: any) {
       return this.api.create('/Supplier-AuthorizedStates/updateLicenseExpiration',data);
   };

    /**
    * Gets State License doucments information
    * @returns {object} promise
    */
    getStateLicenseInfo(authType: string) {
        return this.api.read('/Supplier-AuthorizedStates/getStateLicenseInfo?authType='+authType);
    };

    /**
     * Call back error method
     * @param {json} response
     */
    errorCallBack(response: any) {
      this.api.errorCallback(response);
    };

}