import { Document } from "mongoose";

export interface IFavourite {
    id?: string;
    _id?: string;
    userId: string;
    serviceId: string;
    createdAt: Date;
}

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

export interface IFavouritesAdapter {
    create(data: Omit<CreateFavouriteParams, "sessionUser">): Promise<IFavourite>;
    delete(data: Omit<DeleteFavouriteParams, "sessionUser">): Promise<void>;
    find(filters: Omit<FindFavouritesParams, "sessionUser">): Promise<IFavourite[]>;
    findOne(filters: Omit<FindFavouritesParams, "sessionUser">): Promise<IFavouriteDocument | null>;
    paginate(filters: PaginateFavouritesParams): Promise<PaginateFavouritesResults>;
}

export type FindFavouritesParams = {
    id?: string;
    userId?: string;
    serviceId?: string;
    sessionUser: string;
    startDate?: Date;
    endDate?: Date;
};

export type PaginateFavouritesParams = FindFavouritesParams & {
    page: number;
    limit: number;
};

export type PaginateFavouritesResults = {
    data: IFavourite[];
    page: number;
    pages: number;
};

export type CreateFavouriteParams = {
    userId: string;
    serviceId: string;
    sessionUser: string;
};

export type DeleteFavouriteParams = {
    id: string;
    sessionUser: string;
};

export interface IFavouritesManager {
    favourites: IFavouritesAdapter;
    createFavourite(data: CreateFavouriteParams): Promise<IFavourite>;
    deleteFavourite(data: DeleteFavouriteParams): Promise<void>;
    paginate(data: PaginateFavouritesParams): Promise<PaginateFavouritesResults>;
}