import { TextObjectFilterResult } from "src/Models/TextObjectFilter.model";
import Discounts from "../../Models/Discounts/Discounts";
import {
    CreateDiscountParams,
    DeleteDiscountParams,
    FindDiscountsParams,
    IDiscount,
    PaginateDiscountsParams,
    PaginateDiscountsResults,
} from "../../Models/Discounts/Discounts.Interface";
import { connect } from "mongoose";

export class DiscountsService {
    public async createDiscount(data: CreateDiscountParams): Promise<IDiscount> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        return Discounts.createDiscount(data);
    }

    public async deleteDiscount(data: DeleteDiscountParams): Promise<void> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        return Discounts.deleteDiscount(data);
    }

    public async paginate(data: PaginateDiscountsParams): Promise<PaginateDiscountsResults> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        return Discounts.paginate(data);
    }

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