import { connect } from "mongoose";
import ScheduleList from "../../Models/Schedules/Schedules";
import {
    CreateScheduleParams,
    UpdateScheduleParams,
    DeleteScheduleParams,
    ISchedule,
    PaginateSchedulesParams,
    PaginateSchedulesResults,
    CollaboratorSchedulesView,
    FindSchedulesParams,
} from "../../Models/Schedules/Schedules.Interface";

export class SchedulesService {
    public async createSchedule(data: CreateScheduleParams): Promise<ISchedule> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const newSchedule = await ScheduleList.createSchedule(data);

        return newSchedule;
    }

    public async updateSchedule(data: UpdateScheduleParams): Promise<void> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        await ScheduleList.updateSchedule(data);
    }

    public async deleteSchedule(data: DeleteScheduleParams): Promise<void> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        await ScheduleList.delete(data);
    }

    public async paginateSchedules(
        data: PaginateSchedulesParams
    ): Promise<PaginateSchedulesResults> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const schedules = await ScheduleList.paginate(data);

        return schedules;
    }

    public async findAllSchedulesByCollaborator(
        data: FindSchedulesParams
    ): Promise<CollaboratorSchedulesView> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const schedules = await ScheduleList.findAllSchedulesByCollaborator(data);

        return schedules;
    }
}
