"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildLoggerPurger = exports.LoggerPurgerSchema = void 0;
const datasize_1 = require("@f2/datasize");
const at_1 = require("@f2/at");
const joi_1 = __importDefault(require("@f2/joi"));
const purger_1 = require("./purger");
exports.LoggerPurgerSchema = joi_1.default.object({
    maxAge: joi_1.default.alternatives(joi_1.default.string(), joi_1.default.number().integer().positive()),
    maxSize: joi_1.default.alternatives(joi_1.default.string(), joi_1.default.number().integer().positive())
});
function buildLoggerPurger(path, options) {
    let maxAge;
    let maxSize;
    if (options.maxAge) {
        maxAge = at_1.Interval.from(options.maxAge);
    }
    if (options.maxSize) {
        maxSize = datasize_1.Size.from(options.maxSize).bytes;
    }
    return new purger_1.LoggerPurger(path, maxSize, maxAge);
}
exports.buildLoggerPurger = buildLoggerPurger;
