import { IScheduleDocument } from "./Schedules.Adapter.Mongoose";

export type ScheduleItem = {
    from: string;
    to: string;
    disabled: boolean;
};

export type FindSchedulesParams = {
    _id?: string;
    companyId?: string;
    employeeId?: string;
    weekDay?: number;
};

export type AvailableSchedulesParams = {
    companyId: string;
    employeeId: string;
    weekDay: number;
    from: string;
    to: string;
};

export type PaginateSchedulesParams = FindSchedulesParams & {
    page: number;
    limit: number;
};

export type PaginateSchedulesResults = {
    data: ISchedule[];
    page: number;
    pages: number;
};

export type CreateScheduleParams = {
    companyId: string;
    employeeId: string;
    schedules: Array<ScheduleItem>;
    weekDay: number;
    sessionUser: string;
};

export type UpdateScheduleParams = {
    companyId: string;
    employeeId: string;
    schedules: Array<ScheduleItem>;
    weekDay: number;
    sessionUser: string;
};

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

export type DeleteScheulesByCompanyParams = {
    companyId: string;
};

export type DeleteSchedulesByEmployeeParams = {
    employeeId: string;
};

export interface ISchedule {
    id?: string;
    companyId: string;
    employeeId: string;
    schedules: Array<ScheduleItem>;
    weekDay: number;
}

export interface CollaboratorSchedulesView {
    companyId: string;
    employeeId: string;
    scheduleId: string;
    weekDay: number;
    fullName: string;
    avatar: string;
    schedules: ScheduleItem[];
}

export interface ISchedulesAdapter {
    create(data: CreateScheduleParams): Promise<ISchedule>;
    update(data: UpdateScheduleParams): Promise<void>;
    delete(id: string): Promise<void>;
    find(filters: FindSchedulesParams): Promise<ISchedule[]>;
    findOne(filters: FindSchedulesParams): Promise<IScheduleDocument | null>;
    paginate(filters: PaginateSchedulesParams): Promise<PaginateSchedulesResults>;
}

export interface ISchedulesManager {
    schedules: ISchedulesAdapter;
    createSchedule(data: CreateScheduleParams): Promise<ISchedule>;
    updateSchedule(data: UpdateScheduleParams): Promise<void>;
    find(data: FindSchedulesParams): Promise<ISchedule[]>;
    findAllSchedulesByCollaborator(data: FindSchedulesParams): Promise<CollaboratorSchedulesView>;
    delete(data: DeleteScheduleParams): Promise<void>;
    isAvailable(data: AvailableSchedulesParams): Promise<boolean>;
    deleteSchedulesByCompany(data: DeleteScheulesByCompanyParams): Promise<void>;
    deleteSchedulesByEmployee(data: DeleteSchedulesByEmployeeParams): Promise<void>;
}
