import { connect } from "mongoose";
import SystemNoficationsList from "../../Models/SystemNotifications/SystemNotification";
import {
    DeleteNotificationsByDateParams,
    DeleteSystemNotificationParams,
    FindSystemNotificationsParams,
    PaginateSystemNotificationsParams,
    PaginateSystemNotificationsResults,
    UnreadNotificationResults,
    UpdateSystemNotificationParams,
} from "../../Models/SystemNotifications/SystemNotification.Interface";

export class SystemNotificationsService {
    public async setStateByUser(data: any): Promise<void> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        await SystemNoficationsList.setStateByUser(data);
    }

    public async paginateNotifications(
        data: PaginateSystemNotificationsParams
    ): Promise<PaginateSystemNotificationsResults> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const notifications = await SystemNoficationsList.paginateNotifications(data);

        return notifications;
    }

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

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

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

    public async findUnreadNotifications(
        data: FindSystemNotificationsParams
    ): Promise<UnreadNotificationResults> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        const notifications = await SystemNoficationsList.finUnreadNotifications(data);
        return notifications;
    }
}
