"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _token = require("./token");
var _tdsVersions = require("../tds-versions");
var _helpers = require("./helpers");
const interfaceTypes = {
  0: 'SQL_DFLT',
  1: 'SQL_TSQL'
};
function loginAckParser(buf, offset, _options) {
  // length
  let tokenLength;
  ({
    offset,
    value: tokenLength
  } = (0, _helpers.readUInt16LE)(buf, offset));
  if (buf.length < tokenLength + offset) {
    throw new _helpers.NotEnoughDataError(tokenLength + offset);
  }
  let interfaceNumber;
  ({
    offset,
    value: interfaceNumber
  } = (0, _helpers.readUInt8)(buf, offset));
  const interfaceType = interfaceTypes[interfaceNumber];
  let tdsVersionNumber;
  ({
    offset,
    value: tdsVersionNumber
  } = (0, _helpers.readUInt32BE)(buf, offset));
  const tdsVersion = _tdsVersions.versionsByValue[tdsVersionNumber];
  let progName;
  ({
    offset,
    value: progName
  } = (0, _helpers.readBVarChar)(buf, offset));
  let major;
  ({
    offset,
    value: major
  } = (0, _helpers.readUInt8)(buf, offset));
  let minor;
  ({
    offset,
    value: minor
  } = (0, _helpers.readUInt8)(buf, offset));
  let buildNumHi;
  ({
    offset,
    value: buildNumHi
  } = (0, _helpers.readUInt8)(buf, offset));
  let buildNumLow;
  ({
    offset,
    value: buildNumLow
  } = (0, _helpers.readUInt8)(buf, offset));
  return new _helpers.Result(new _token.LoginAckToken({
    interface: interfaceType,
    tdsVersion: tdsVersion,
    progName: progName,
    progVersion: {
      major: major,
      minor: minor,
      buildNumHi: buildNumHi,
      buildNumLow: buildNumLow
    }
  }), offset);
}
var _default = exports.default = loginAckParser;
module.exports = loginAckParser;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 5248 characters]