import PlanSubscriptionsList from "../../Models/PlanSubscriptions/PlanSubscriptons";
import {
    CancellPlanSuscriptionParams,
    CreateMPPreApprovalParams,
    GetSubscriptionInitPointParams,
    GetSuscriptionInitPointResponse,
    MPPreApprovalResponse,
} from "../../Models/PlanSubscriptions/PlanSubscriptions.interface";
import { connect } from "mongoose";

export class PlanSubscriptionsService {
    public async getInitPoint(
        data: GetSubscriptionInitPointParams
    ): Promise<GetSuscriptionInitPointResponse> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        const initPoint = await PlanSubscriptionsList.getInitPoint(data);
        return initPoint;
    }

    public async create(data: CreateMPPreApprovalParams): Promise<MPPreApprovalResponse> {
        await connect(`${process.env.DATABASE_CONNECTION}`);
        const preApproval = await PlanSubscriptionsList.create(data);
        return preApproval;
    }

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