"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NoPrinter = exports.Printer = void 0;
const colors_1 = __importDefault(require("colors"));
const path_1 = __importDefault(require("path"));
const guards_1 = require("./guards");
const stepTag = colors_1.default.bold(colors_1.default.magenta('Step'));
const flowTag = colors_1.default.bold(colors_1.default.blue('Flow'));
const streamTag = colors_1.default.bold(colors_1.default.green('Stream'));
const created = colors_1.default.green('➜ [CREATED]');
const building = colors_1.default.yellow('⚡ [BUILDING]');
const built = colors_1.default.green('✓ [BUILT]');
const updated = colors_1.default.yellow('➜ [UPDATED]');
const removed = colors_1.default.red('➜ [REMOVED]');
const invalidEmit = colors_1.default.red('➜ [INVALID EMIT]');
const error = colors_1.default.red('[ERROR]');
class Printer {
    constructor(baseDir) {
        this.baseDir = baseDir;
        this.stepTag = stepTag;
        this.flowTag = flowTag;
        this.created = created;
        this.building = building;
        this.built = built;
        this.updated = updated;
        this.removed = removed;
    }
    printInvalidEmit(step, emit) {
        console.log(`${invalidEmit} ${stepTag} ${this.getStepType(step)} ${this.getStepPath(step)} tried to emit an event not defined in the step config: ${colors_1.default.yellow(emit)}`);
    }
    printStepCreated(step) {
        console.log(`${created} ${stepTag} ${this.getStepType(step)} ${this.getStepPath(step)} created`);
    }
    printStepUpdated(step) {
        console.log(`${updated} ${stepTag} ${this.getStepType(step)} ${this.getStepPath(step)} updated`);
    }
    printStepRemoved(step) {
        console.log(`${removed} ${stepTag} ${this.getStepType(step)} ${this.getStepPath(step)} removed`);
    }
    printFlowCreated(flowName) {
        console.log(`${created} ${flowTag} ${colors_1.default.bold(colors_1.default.cyan(flowName))} created`);
    }
    printFlowUpdated(flowName) {
        console.log(`${updated} ${flowTag} ${colors_1.default.bold(colors_1.default.cyan(flowName))} updated`);
    }
    printFlowRemoved(flowName) {
        console.log(`${removed} ${flowTag} ${colors_1.default.bold(colors_1.default.cyan(flowName))} removed`);
    }
    printStreamCreated(stream) {
        console.log(`${created} ${streamTag} ${this.getStreamPath(stream)} created`);
    }
    printStreamUpdated(stream) {
        console.log(`${updated} ${streamTag} ${this.getStreamPath(stream)} updated`);
    }
    printStreamRemoved(stream) {
        console.log(`${removed} ${streamTag} ${this.getStreamPath(stream)} removed`);
    }
    printInvalidSchema(topic, step) {
        console.log(`${error} Topic ${colors_1.default.bold(colors_1.default.blue(topic))} has incompatible schemas in the following steps:`);
        step.forEach((step) => {
            console.log(`${colors_1.default.red('  ✖')} ${this.getStepPath(step)}`);
        });
    }
    printValidationError(stepPath, validationError) {
        const relativePath = this.getRelativePath(stepPath);
        console.log(`${error} ${colors_1.default.bold(colors_1.default.cyan(relativePath))}`);
        validationError.errors?.forEach((error) => {
            if (error.path) {
                console.log(`${colors_1.default.red('│')} ${colors_1.default.yellow(`✖ ${error.path}`)}: ${error.message}`);
            }
            else {
                console.log(`${colors_1.default.red('│')} ${colors_1.default.yellow('✖')} ${error.message}`);
            }
        });
        console.log(`${colors_1.default.red('└─')} ${colors_1.default.red(validationError.error)}  `);
    }
    getRelativePath(filePath) {
        return path_1.default.relative(this.baseDir, filePath);
    }
    getStepType(step) {
        if ((0, guards_1.isApiStep)(step))
            return colors_1.default.gray('(API)');
        if ((0, guards_1.isEventStep)(step))
            return colors_1.default.gray('(Event)');
        if ((0, guards_1.isCronStep)(step))
            return colors_1.default.gray('(Cron)');
        if ((0, guards_1.isNoopStep)(step))
            return colors_1.default.gray('(Noop)');
        return colors_1.default.gray('(Unknown)');
    }
    getStepPath(step) {
        const stepPath = this.getRelativePath(step.filePath);
        return colors_1.default.bold(colors_1.default.cyan(stepPath));
    }
    getStreamPath(stream) {
        const streamPath = this.getRelativePath(stream.filePath);
        return colors_1.default.bold(colors_1.default.magenta(streamPath));
    }
}
exports.Printer = Printer;
class NoPrinter extends Printer {
    constructor(baseDir) {
        super(baseDir);
    }
    printInvalidEmit() { }
    printStepCreated() { }
    printStepUpdated() { }
    printStepRemoved() { }
    printFlowCreated() { }
    printFlowUpdated() { }
    printFlowRemoved() { }
    printStepType() { }
    printStepPath() { }
    printStreamCreated() { }
    printStreamUpdated() { }
    printStreamRemoved() { }
}
exports.NoPrinter = NoPrinter;
