import { TextObjectFilterResult } from "../../Models/TextObjectFilter.model";
import AppointmentList from "../../Models/Appointments/Appointments";
import {
    AppointmentAdminByClientView,
    AppointmentAdminByDateView,
    CreateAppointmentParams,
    MoveAppointmentParams, ChangeServiceParams,
    DeleteAppointmentParams,
    FindAppointmentsParams,
    FindAppointmentSchedulesParams,
    IAppointment,
    UpdateAppointmentParams,
    FindAppointmentsByUserParams,
    FindAppointmentsByCollaboratorParams,
    SendAppointmentNotificationParams,
    GetAppointmentEventParams,
    AppointmentEventByClient,
    ApplyAppointmentDiscountParams,
    DeleteAppointmentDiscountParams,
    SendWapSystemNotificationParams,
    GetAvailableDatesParams,
    GetAvailableDatesResult,
    FindAppointmentsByUserPaginatedParams,
    FindAppointmentsByCollaboratorPaginatedParams,
    PaginatedAppointmentEventByClientResult,
} from "../../Models/Appointments/Appointments.Interface";
import { connect } from "mongoose";

export class AppointmentService {
    public async createAppointment(data: CreateAppointmentParams): Promise<IAppointment> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const newAppointment = await AppointmentList.createAppointment(data);

        return newAppointment;
    }


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

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

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

        await AppointmentList.updateAppointment(data);
    }

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

        await AppointmentList.deleteAppointment(data);
    }

    public async findAppointmentsAdminByDate(
        data: FindAppointmentsParams
    ): Promise<AppointmentAdminByDateView> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const appointments = await AppointmentList.findAppointmentsAdminByDate(data);

        return appointments;
    }

    public async getAppointmentEvent(
        data: GetAppointmentEventParams
    ): Promise<AppointmentEventByClient> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const appointment = await AppointmentList.getAppointmentEvent(data);

        return appointment;
    }

    public async findAppointmentsAdminByClient(
        data: FindAppointmentsParams
    ): Promise<AppointmentAdminByClientView> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const appointments = await AppointmentList.findAppointmentsAdminByClient(data);

        return appointments;
    }

    public async findAppointmentsByUser(
        data: FindAppointmentsByUserParams
    ): Promise<AppointmentAdminByClientView> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const appointments = await AppointmentList.findAppointmentsByUser(data);

        return appointments;
    }

    public async findAppointmentsByCollaborator(
        data: FindAppointmentsByCollaboratorParams
    ): Promise<AppointmentAdminByClientView> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const appointments = await AppointmentList.findAppointmentsByCollaborator(data);

        return appointments;
    }

    public async findAppointmentsByUserPaginated(
        data: FindAppointmentsByUserPaginatedParams
    ): Promise<PaginatedAppointmentEventByClientResult> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const appointments = await AppointmentList.findAppointmentsByUserPaginated(data);

        return appointments;
    }

    public async findAppointmentsByCollaboratorPaginated(
        data: FindAppointmentsByCollaboratorPaginatedParams
    ): Promise<PaginatedAppointmentEventByClientResult> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const appointments = await AppointmentList.findAppointmentsByCollaboratorPaginated(data);

        return appointments;
    }

    public async getSchedules(
        data: FindAppointmentSchedulesParams
    ): Promise<TextObjectFilterResult[]> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        const schedules = await AppointmentList.getSchedules(data);
        return schedules;
    }

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

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

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

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

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

    public async getAvailableDates(
        data: GetAvailableDatesParams
    ): Promise<GetAvailableDatesResult> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        return AppointmentList.getAvailableDates(data);
    }
}
