"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

function _path() {
  const data = _interopRequireDefault(require("path"));

  _path = function () {
    return data;
  };

  return data;
}

function _fsExtra() {
  const data = _interopRequireDefault(require("fs-extra"));

  _fsExtra = function () {
    return data;
  };

  return data;
}

function _logger() {
  const data = _interopRequireDefault(require("../logger/logger"));

  _logger = function () {
    return data;
  };

  return data;
}

function errors() {
  const data = _interopRequireWildcard(require("./exceptions"));

  errors = function () {
    return data;
  };

  return data;
}

class GitHook {
  constructor(hooksDirPath, name, content) {
    this.hooksDirPath = hooksDirPath;
    this.name = name;
    this.content = content;
  }

  get fullPath() {
    return _path().default.join(this.hooksDirPath, this.name);
  }

  isExistSync() {
    return _fsExtra().default.existsSync(this.fullPath);
  }

  writeSync(override = false, throws = false) {
    const exist = this.isExistSync();

    if (exist && !override) {
      if (throws) throw new (errors().GitHookAlreadyExists)(this.name);
      return null;
    }

    _fsExtra().default.writeFileSync(this.fullPath, this.content);

    return true;
  }

}

exports.default = GitHook;