text: 'use strict';
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  
  var _PropertyResponse2 = require('../PropertyResponse');
  
  var _PropertyResponse3 = _interopRequireDefault(_PropertyResponse2);
  
  var _PropertyDecoder = require('../PropertyDecoder');
  
  var _PropertyDecoder2 = _interopRequireDefault(_PropertyDecoder);
  
  var _autoApis = require('../autoApis');
  
  var _autoApis2 = _interopRequireDefault(_autoApis);
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  
  function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  
  var FAILURE_REASONS = {
    0: 'Unsupported Capability - Car has not the capability to perform the command',
    1: 'Unauthorised - User has not been authenticated or lacks permissions',
    2: 'Incorrect State - Command can not be executed in the current car state',
    3: 'Execution Timeout - Command failed to execute in time for an unknown reason',
    4: 'Vehicle Asleep - Car has to be waken up before the command can be used. If this is for a virtual car, the emulator has to be loaded',
    5: 'Invalid Auto Command - Auto API command not recognised',
    6: 'Pending - Capability is being refreshed',
    7: 'Rate Limit - Capability rate limit has been exceeded'
  };
  
  var FailureMessageResponse = function (_PropertyResponse) {
    _inherits(FailureMessageResponse, _PropertyResponse);
  
    /**
     * @property {Object} autoApi (Object `{label: (string), lsb: (number), namespace: (string)}`) AutoApi
     * @property {Number} type (number) Failure type
     * @property {Object} reason (Object `{key: (number), value: (string)}`) Failure reason
     *
     * @example FailureMessageResponse
      {
        autoApi: {
          label: 'Trunk Access',
          lsb: 33,
          namespace: 'trunkAccess',
        },
        type: 0,
        reason: {
          key: 1,
          value:
          'Unauthorised - User has not been authenticated or lacks permissions',
        },
      }
     */
    function FailureMessageResponse(data, config) {
      _classCallCheck(this, FailureMessageResponse);
  
      var _this = _possibleConstructorReturn(this, (FailureMessageResponse.__proto__ || Object.getPrototypeOf(FailureMessageResponse)).call(this));
  
      var properties = [new _PropertyDecoder2.default(0x01, 'autoApi').setDecoder(_this.failedCapabilityDecoder), new _PropertyDecoder2.default(0x02, 'type'), new _PropertyDecoder2.default(0x03, 'reason').setDecoder(_this.reasonDecoder)];
  
      _this.parse(data, properties, config);
      return _this;
    }
  
    _createClass(FailureMessageResponse, [{
      key: 'failedCapabilityDecoder',
      value: function failedCapabilityDecoder(bytes) {
        var autoApi = Object.values(_autoApis2.default).find(function (api) {
          return api.lsb === bytes[1];
        });
  
        return !!autoApi ? {
          label: autoApi.label,
          namespace: autoApi.namespace,
          lsb: autoApi.lsb
        } : {
          lsb: bytes[1]
        };
      }
    }, {
      key: 'reasonDecoder',
      value: function reasonDecoder(bytes) {
        return {
          key: bytes[0],
          value: FAILURE_REASONS[bytes[0]]
        };
      }
    }]);
  
    return FailureMessageResponse;
  }(_PropertyResponse3.default);
  
  FailureMessageResponse.identifier = [0x00, 0x02];
  exports.default = FailureMessageResponse;