import { DiscountType } from "../Discounts/Discounts.Interface";
import { IRepeatDocument } from "./Repeats.Adapter.Mongoose";

export type FindRepeatsParams = {
    _id?: string;
    companyId?: string;
    employeeId?: string;
    serviceId?: string;
    clientId?: string;
    weekDay?: number;
    startHour?: number;
};

export type CreateRepeatsParams = {
    companyId: string;
    employeeId: string;
    serviceId: string;
    discountId?: string;
    clientId: string;
    weekDay: number;
    startHour: number;
    sessionUser: string;
};

export type DeleteRepeatsParams = {
    repeatId: string;
    sessionUser: string;
};

export type CountRepeatsParams = {
    companyId: string;
    employeeId: string;
    countDate: Date;
    heatMapFraction: number;
};

export type AddRepeatDisabledDateParams = {
    repeatId: string;
    disableDate: Date;
    sessionUser: string;
};

export type DeleteRepeatsByCompanyParams = {
    companyId: string;
};

export type DeleteRepeatsByClientParams = {
    clientId: string;
};

export type DeleteRepeatsByUserParams = {
    userId: string;
};

export type GetPendingRepeatsParams = {
    companyId?: string;
    employeeId?: string;
    sessionUser: string;
    filterBySessionUser?: boolean;
};

export interface IRepeat {
    id?: string;
    companyId: string;
    employeeId: string;
    serviceId: string;
    discountId?: string;
    clientId: string;
    weekDay: number;
    startHour: number;
    length: number;
    disabledDates?: Date[];
}

export interface RepeatView {
    id: string;
    weekDay: number;
    weekDayName: string;
    startHour: number;
    startHourFormatted: string;
    length: number;
    companyId: string;
    companyName: string;
    employeeId: string;
    employeeName: string;
    employeeCalendarColor: string;
    employeeAvatar: string;
    serviceId: string;
    serviceName: string;
    discountId: string;
    discountType: DiscountType;
    discountValue: number;
    discountName: string;
    discountCode: string;
    clientId: string;
    clientName: string;
}

export interface PendingRepeatView extends RepeatView {
    pendingDate: Date;
}

export interface IRepeatsAdapter {
    create(data: CreateRepeatsParams): Promise<IRepeat>;
    delete(id: string): Promise<void>;
    find(filters: FindRepeatsParams): Promise<IRepeat[]>;
    findOne(filters: FindRepeatsParams): Promise<IRepeatDocument | null>;
}

export interface IRepeatsManager {
    repeats: IRepeatsAdapter;
    createRepeat(data: CreateRepeatsParams): Promise<IRepeat>;
    deleteRepeat(data: DeleteRepeatsParams): Promise<void>;
    deleteRepeatsByCompany(data: DeleteRepeatsByCompanyParams): Promise<void>;
    deleteRepeatsByClient(data: DeleteRepeatsByClientParams): Promise<void>;
    deleteRepeatsByUser(data: DeleteRepeatsByUserParams): Promise<void>;
    getRepeatsByClient(data: FindRepeatsParams): Promise<RepeatView[]>;
    countRepeats(data: CountRepeatsParams): Promise<number>;
    addDisabledDate(data: AddRepeatDisabledDateParams): Promise<void>;
    existDisabledDate(checkDate: Date, disabledDates: Date[]): boolean;
    getPendingRepeatsCurrentWeek(data: GetPendingRepeatsParams): Promise<PendingRepeatView[]>;
}
