import { connect } from "mongoose";
import SchedulesEnabledList from "../../Models/SchedulesEnabled/SchedulesEnabled";
import {
    CreateSchedulesEnabledParams,
    DeleteSchedulesEnabledParams,
    ISchedulesEnabled,
    FindSchedulesEnabledParams,
    SchedulesEnabledView,
    EnableScheduleParams,
} from "../../Models/SchedulesEnabled/SchedulesEnabled.Interface";

export class SchedulesEnabledService {
    public async createSchedulesEnabled(
        data: CreateSchedulesEnabledParams
    ): Promise<ISchedulesEnabled> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const newSchedulesEnabled = await SchedulesEnabledList.createSchedulesEnabled(data);

        return newSchedulesEnabled;
    }

    public async find(data: FindSchedulesEnabledParams): Promise<SchedulesEnabledView[]> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const schedulesEnabled = await SchedulesEnabledList.find(data);

        return schedulesEnabled;
    }

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

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

    public async deleteSchedulesEnabled(data: DeleteSchedulesEnabledParams): Promise<void> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        await SchedulesEnabledList.delete(data);
    }

    public async getSchedulesEnabled(
        data: FindSchedulesEnabledParams
    ): Promise<ISchedulesEnabled | null> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const schedulesEnabled = await SchedulesEnabledList.findOne(data);

        return schedulesEnabled;
    }
}
