import { connect } from "mongoose";
import Templates from "../../Models/Templates/Templates";
import {
    DeleteTemplateParams,
    FindTemplatesParams,
    GetDefaultTemplateParams,
    ITemplate,
    PaginateTemplatesParams,
    PaginateTemplatesResults,
    SaveTemplateParams,
} from "../../Models/Templates/Templates.Interface";
import { TextObjectFilterResult } from "../../Models/TextObjectFilter.model";

export class TemplatesService {
    public async saveTemplate(data: SaveTemplateParams): Promise<ITemplate> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        return Templates.saveTemplate(data);
    }

    public async deleteTemplate(data: DeleteTemplateParams): Promise<void> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        return Templates.deleteTemplate(data);
    }

    public async paginate(data: PaginateTemplatesParams): Promise<PaginateTemplatesResults> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        return Templates.paginate(data);
    }

    public async getTemplate(data: FindTemplatesParams): Promise<ITemplate> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        return Templates.getTemplate(data);
    }

    public async textObjectFilter(data: FindTemplatesParams): Promise<TextObjectFilterResult[]> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        const discounts = await Templates.textObjectFilter(data);
        return discounts;
    }

    public async getDefaultTemplate(data: GetDefaultTemplateParams): Promise<string> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        const template = await Templates.getDefaultTemplate(data);
        return template;
    }
}
