import { Document } from "mongoose";
import { TextObjectFilterResult } from "../TextObjectFilter.model";

export enum DiscountType {
    FIXED = "fixed",
    PERCENTAGE = "percentage",
}

export interface IDiscount {
    id?: string;
    _id?: string;
    companyId: string;
    name: string;
    code: string;
    type: DiscountType;
    value: number;
    createdAt: Date;
}

export interface IDiscountDocument extends Omit<IDiscount, "id" | "_id">, Document {
    _id: string;
}

export interface IDiscountsAdapter {
    create(data: Omit<CreateDiscountParams, "sessionUser">): Promise<IDiscount>;
    delete(data: Omit<DeleteDiscountParams, "sessionUser">): Promise<void>;
    find(filters: Omit<FindDiscountsParams, "sessionUser">): Promise<IDiscount[]>;
    findOne(filters: Omit<FindDiscountsParams, "sessionUser">): Promise<IDiscountDocument | null>;
    paginate(filters: PaginateDiscountsParams): Promise<PaginateDiscountsResults>;
}

export type FindDiscountsParams = {
    id?: string;
    companyId: string;
    code?: string;
    type?: DiscountType;
    sessionUser: string;
    startDate?: Date;
    endDate?: Date;
    startValue?: number;
    endValue?: number;
};

export type PaginateDiscountsParams = FindDiscountsParams & {
    page: number;
    limit: number;
};

export type PaginateDiscountsResults = {
    data: IDiscount[];
    page: number;
    pages: number;
};

export type CreateDiscountParams = {
    companyId: string;
    name: string;
    code: string;
    type: DiscountType;
    value: number;
    sessionUser: string;
};

export type DeleteDiscountParams = {
    id: string;
    companyId: string;
    sessionUser: string;
};

export type DeleteDiscountsByCompanyParams = {
    companyId: string;
};

export interface IDiscountsManager {
    discounts: IDiscountsAdapter;
    deleteDiscountsByCompany(data: DeleteDiscountsByCompanyParams): Promise<void>;
    createDiscount(data: CreateDiscountParams): Promise<IDiscount>;
    deleteDiscount(data: DeleteDiscountParams): Promise<void>;
    paginate(data: PaginateDiscountsParams): Promise<PaginateDiscountsResults>;
    textObjectFilter(data: FindDiscountsParams): Promise<TextObjectFilterResult[]>;
}
