'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 _path;

function _load_path() {
  return _path = _interopRequireDefault(require('path'));
}

var _fsExtra;

function _load_fsExtra() {
  return _fsExtra = _interopRequireDefault(require('fs-extra'));
}

var _logger;

function _load_logger() {
  return _logger = _interopRequireDefault(require('../logger/logger'));
}

var _exceptions;

function _load_exceptions() {
  return _exceptions = _interopRequireWildcard(require('./exceptions'));
}

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

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"); } }

var GitHook = function () {
  function GitHook(hooksDirPath, name, content) {
    _classCallCheck(this, GitHook);

    this.hooksDirPath = hooksDirPath;
    this.name = name;
    this.content = content;
  }

  _createClass(GitHook, [{
    key: 'isExistSync',
    value: function isExistSync() {
      return (_fsExtra || _load_fsExtra()).default.existsSync(this.fullPath);
    }
  }, {
    key: 'writeSync',
    value: function writeSync() {
      var override = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
      var throws = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

      var exist = this.isExistSync();
      if (exist && !override) {
        if (throws) throw new (_exceptions || _load_exceptions()).GitHookAlreadyExists(this.name);
        return null;
      }
      (_fsExtra || _load_fsExtra()).default.writeFileSync(this.fullPath, this.content);
      return true;
    }
  }, {
    key: 'fullPath',
    get: function get() {
      return (_path || _load_path()).default.join(this.hooksDirPath, this.name);
    }
  }]);

  return GitHook;
}();

exports.default = GitHook;