import path, { dirname } from "path";
import { ResourceProcessor } from "../types";
import { Resource, ResourceStatus, db } from "@nice/common";
import { Logger } from "@nestjs/common";
import fs from 'fs/promises';

export abstract class BaseProcessor implements ResourceProcessor {
    constructor() { }
    protected logger = new Logger(BaseProcessor.name)

    abstract process(resource: Resource): Promise<Resource>
    protected createOutputDir(filepath: string, subdirectory: string = 'assets'): string {
        const outputDir = path.join(
            path.dirname(filepath),
            subdirectory,
        );
        fs.mkdir(outputDir, { recursive: true }).catch(err => this.logger.error(`Failed to create directory: ${err.message}`));

        return outputDir;

    }
}
//