import { IHttpService, IQService } from 'angular';
import { IPromise } from 'q';
import { Magento2ApiService } from '../Magento2ApiService';
import { IMagento2Attribute } from './magento2.attribute';

export class Magento2ProductAttributesApiService extends Magento2ApiService<IMagento2Attribute> {

  private static _checkValidAttribute(attribute): void {
    if (attribute == null || attribute === '') {
      throw new TypeError('Identifier cannot be empty.');
    }
  }

  constructor(
    public $http: IHttpService,
    public $q: IQService,
    public API_URL: string,
    public API_PRODUCT_ATTRIBUTES_ENDPOINT: string
  ) {
    super($http, $q, API_URL, API_PRODUCT_ATTRIBUTES_ENDPOINT);
  }

  public get(
    attribute: string
  ): IPromise<IMagento2Attribute> {
    Magento2ProductAttributesApiService._checkValidAttribute(attribute);

    return this._get(attribute);
  }
}
