import { connect } from "mongoose";
import {
    CreateCashFlowParams,
    DeleteByClientAccountMovementParams,
    DeleteMovementByPaymentParams,
    DeleteMovementParams,
    FindCashFlowParams,
    PaginateCashFlowParams,
    PaginateCashFlowResults,
} from "../../Models/CashFlow/CashFlow.Interface";
import CashFlowBalance from "../../Models/CashFlowBalance/CashFlowBalance";
import {
    CalculateCashFlowBalanceParams,
    CashFlowHistoryView,
    FindCashFlowBalanceParams,
    ICashFlowBalance,
} from "../../Models/CashFlowBalance/CashFlowBalance.Interface";
import CashFlow from "../../Models/CashFlow/CashFlow";

export class CashFlowService {
    public async createCashFlowMovements(data: CreateCashFlowParams): Promise<void> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        await CashFlowBalance.createCashFlowMovement(data);
    }

    public async calculateBalance(data: CalculateCashFlowBalanceParams): Promise<ICashFlowBalance> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        return await CashFlowBalance.calculateBalance(data);
    }

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

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

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

    public async history(data: FindCashFlowBalanceParams): Promise<CashFlowHistoryView> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        return await CashFlowBalance.history(data);
    }

    public async paginate(data: PaginateCashFlowParams): Promise<PaginateCashFlowResults> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        return await CashFlow.paginate(data);
    }

    public async getCashFlowBlaance(data: FindCashFlowParams): Promise<number> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        return await CashFlow.getCashFlowBalance(data);
    }
}
