import { connect } from "mongoose";
import Payments from "../../Models/Payments/Payments";
import {
    CreatePaymentParams,
    DeletePaymentParams,
    FindPaymentsParams,
    GetAppointmentPaymentsParams,
    IPayment,
    MarkAsPayedParams,
    PaginateNotPayedAppointmentsParams,
    PaginateNotPayedAppointmentsResult,
    NotPayedReportResult,
    PaginatePaymentsViewParams,
    PaginatePaymentsViewResults,
} from "../../Models/Payments/Payments.Interface";

export class PaymentsService {
    public async getPaymentsReport(data: FindPaymentsParams) {
        return await Payments.getPaymentsReport(data);
    }

    public async createPayment(data: CreatePaymentParams): Promise<IPayment> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const payment = await Payments.createPayment(data);

        return payment;
    }

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

        await Payments.deletePayment(data);
    }

    public async getAppointmentPayments(data: GetAppointmentPaymentsParams): Promise<IPayment[]> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        const payments = await Payments.getAppointmentPayments(data);

        return payments;
    }

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

        await Payments.markAsPayed(data);
    }

    public async paginatedPaymentsViewTotal(data: FindPaymentsParams): Promise<number> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        return await Payments.paginatedPaymentsViewTotal(data);
    }

    public async paginatePaymentsView(
        data: PaginatePaymentsViewParams
    ): Promise<PaginatePaymentsViewResults> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        return await Payments.paginatePaymentsView(data);
    }

    public async paginateNotPayedAppointments(
        data: PaginateNotPayedAppointmentsParams
    ): Promise<PaginateNotPayedAppointmentsResult> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        return await Payments.paginateNotPayedAppointments(data);
    }

    public async paginatedNotPayedAppiontmentsTotal(data: FindPaymentsParams): Promise<number> {
        await connect(`${process.env.DATABASE_CONNECTION}`);

        return await Payments.paginatedNotPayedAppiontmentsTotal(data);
    }

    
    public async getNotPayedReport(data: FindPaymentsParams): Promise<NotPayedReportResult> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        return await Payments.getNotPayedReport(data);
    }

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

        await Payments.payNotPayedAppointments(data);
    }
}
