import { createLogger } from "../logger/logger.js";

interface Data {
    success: boolean;
    module: string;
    subModule?: string;
    level: "info" | "error" | "debug" | "fatal";
    message: string;
    data: unknown[];
    notify?: boolean;
}

/**
 * This dose the return process and log at the same time, vs needing to log and return at the same time.
 * When to use.
 *  * APIs
 *  * actual returns and needing to stop.
 * @param Data
 * @returns
 */
export const returnFunc = (data: Data) => {
    const log = createLogger({ module: data.module });

    switch (data.level) {
        case "info":
            log.info({ notify: data.notify }, data.message);
            break;
        case "error":
            log.error({ notify: data.notify }, data.message);
            break;
        case "debug":
            log.debug({ notify: data.notify }, data.message);
            break;
        case "fatal":
            log.fatal({ notify: data.notify }, data.message);
    }

    return {
        success: data.success,
        message: data.message,
        data: [],
    };
};
