"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DxLogger = exports.getQueueName = void 0;
const chalk_1 = __importDefault(require("chalk"));
function getQueueName(endpoint) {
    return new URL(endpoint).pathname;
}
exports.getQueueName = getQueueName;
class DxLogger {
    started(address = "localhost:9181", telemetryEnabled = true) {
        console.log((0, chalk_1.default) `
{yellow Quirrel}
{yellow =======}
Welcome to the Quirrel development server.

Open your browser and go to
    {yellow http://${address}}
to get a better overview over pending jobs.
${telemetryEnabled
            ? (0, chalk_1.default) `
Quirrel collects {black completely anonymous}
telemetry data about general usage,
opt-out by setting the {yellow DISABLE_TELEMETRY}
environment variable.
`
            : ""}
Listening on {yellow ${address}}.`.trim());
    }
    executionErrored(job, error) {
        console.error("Caught error during execution:", error, job);
    }
    jobCreated(job) {
        var _a;
        if (job.id === "@cron") {
            console.log((0, chalk_1.default) `
⏰Registered a Cron Job
   {gray endpoint:} {yellow ${getQueueName(job.endpoint)}}
   {gray schedule:} {yellow ${(_a = job.repeat) === null || _a === void 0 ? void 0 : _a.cron}}`);
            return;
        }
        console.log((0, chalk_1.default) `
📝Created Job
   {gray queue:} {yellow ${getQueueName(job.endpoint)}}
      {gray id:} {yellow ${job.id}}
    {gray body:} {yellow ${job.body}}`);
    }
    cronUpdated(crons, deleted) {
        if (crons.dryRun) {
            return;
        }
        console.log("\n⏰Updated Cron jobs");
        console.log(crons.crons
            .map((c) => (0, chalk_1.default) `  {yellow ${c.route}:} {green ${c.schedule}}`)
            .join("\n"));
        if (deleted.length) {
            console.log((0, chalk_1.default) `  {red obsolete:} {yellow ${deleted.join(", ")}}`);
        }
    }
    jobDeleted(job) {
        if (job.id === "@cron") {
            console.log((0, chalk_1.default) `
⏰Unregistered a Cron Job
   {gray endpoint:} {yellow ${getQueueName(job.endpoint)}}`);
            return;
        }
    }
    startingExecution(job) {
        console.log((0, chalk_1.default) `
👟Executing job
  {gray queue:} {yellow ${getQueueName(job.endpoint)}}
     {gray id:} {yellow ${job.id}}
   {gray body:} {yellow ${job.body}}`);
        return () => {
            console.log("\n" + (0, chalk_1.default) `✔️ Successfully executed {yellow ${job.id}}.`);
        };
    }
}
exports.DxLogger = DxLogger;
//# sourceMappingURL=dx-logger.js.map