function getType(options) {
  const optional = options.optional ? options.default !== void 0 ? false : true : false;
  return `${options.type}${optional ? " | undefined" : ""}`;
}
const stringValidator = (input) => {
  return {
    valid: typeof input === "string",
    parsed: input
  };
};
const numberValidator = (input) => {
  const num = parseFloat(input ?? "");
  return {
    valid: !isNaN(num),
    parsed: num
  };
};
const booleanValidator = (input) => {
  const bool = input === "true" ? true : input === "false" ? false : void 0;
  return {
    valid: typeof bool === "boolean",
    parsed: bool
  };
};
function validateEnvVariable(value, options) {
  const validator = {
    string: stringValidator,
    number: numberValidator,
    boolean: booleanValidator
  }[options.type];
  const type = getType(options);
  if (options.optional || options.default !== void 0) {
    if (value === void 0) {
      return {
        ok: true,
        value: options.default,
        type
      };
    }
  }
  const { valid, parsed } = validator(value);
  if (valid) {
    return {
      ok: true,
      value: parsed,
      type
    };
  }
  return {
    ok: false,
    type
  };
}
export {
  getType,
  validateEnvVariable
};
