import { connect } from "mongoose";
import SchedulesDisabledList from "../../Models/SchedulesDisabled/SchedulesDisabled";
import {
    CreateSchedulesDisabledParams,
    DeleteSchedulesDisabledParams,
    DisableScheduleParams,
    FindSchedulesDisabledParams,
    ISchedulesDisabled,
    SchedulesDisabledByCollaboratorView,
} from "../../Models/SchedulesDisabled/SchedulesDisabled.Interface";

export class SchedulesDisabledService {
    public async createSchedulesDisabled(data: CreateSchedulesDisabledParams): Promise<ISchedulesDisabled> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const newSchedulesDisabled = await SchedulesDisabledList.createSchedulesDisabled(data);

        return newSchedulesDisabled;
    }

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

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

    public async deleteSchedulesDisabled(data: DeleteSchedulesDisabledParams): Promise<void> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        await SchedulesDisabledList.delete(data);
    }

    public async getSchedulesDisabled(data: FindSchedulesDisabledParams): Promise<ISchedulesDisabled | null> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const schedulesDisabled = await SchedulesDisabledList.findOne(data);

        return schedulesDisabled;
    }

    public async findSchedulesDisabledByCollaborator(
        data: FindSchedulesDisabledParams
    ): Promise<SchedulesDisabledByCollaboratorView> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const schedulesDisabled = await SchedulesDisabledList.findSchedulesDisabledByCollaborator(data);

        return schedulesDisabled;
    }
}
