module.exports = {

"[project]/.next-internal/server/app/api/adminapi/wallet/withdraw/route/actions.js [app-rsc] (server actions loader, ecmascript)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
}}),
"[externals]/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js [external] (next/dist/compiled/next-server/app-route-turbo.runtime.dev.js, cjs)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
const mod = __turbopack_context__.x("next/dist/compiled/next-server/app-route-turbo.runtime.dev.js", () => require("next/dist/compiled/next-server/app-route-turbo.runtime.dev.js"));

module.exports = mod;
}}),
"[externals]/next/dist/compiled/@opentelemetry/api [external] (next/dist/compiled/@opentelemetry/api, cjs)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
const mod = __turbopack_context__.x("next/dist/compiled/@opentelemetry/api", () => require("next/dist/compiled/@opentelemetry/api"));

module.exports = mod;
}}),
"[externals]/next/dist/compiled/next-server/app-page-turbo.runtime.dev.js [external] (next/dist/compiled/next-server/app-page-turbo.runtime.dev.js, cjs)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
const mod = __turbopack_context__.x("next/dist/compiled/next-server/app-page-turbo.runtime.dev.js", () => require("next/dist/compiled/next-server/app-page-turbo.runtime.dev.js"));

module.exports = mod;
}}),
"[externals]/next/dist/server/app-render/work-unit-async-storage.external.js [external] (next/dist/server/app-render/work-unit-async-storage.external.js, cjs)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
const mod = __turbopack_context__.x("next/dist/server/app-render/work-unit-async-storage.external.js", () => require("next/dist/server/app-render/work-unit-async-storage.external.js"));

module.exports = mod;
}}),
"[externals]/next/dist/server/app-render/work-async-storage.external.js [external] (next/dist/server/app-render/work-async-storage.external.js, cjs)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
const mod = __turbopack_context__.x("next/dist/server/app-render/work-async-storage.external.js", () => require("next/dist/server/app-render/work-async-storage.external.js"));

module.exports = mod;
}}),
"[externals]/next/dist/server/app-render/after-task-async-storage.external.js [external] (next/dist/server/app-render/after-task-async-storage.external.js, cjs)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
const mod = __turbopack_context__.x("next/dist/server/app-render/after-task-async-storage.external.js", () => require("next/dist/server/app-render/after-task-async-storage.external.js"));

module.exports = mod;
}}),
"[externals]/mongoose [external] (mongoose, cjs)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
const mod = __turbopack_context__.x("mongoose", () => require("mongoose"));

module.exports = mod;
}}),
"[externals]/crypto [external] (crypto, cjs)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
const mod = __turbopack_context__.x("crypto", () => require("crypto"));

module.exports = mod;
}}),
"[project]/models/user.ts [app-route] (ecmascript)": ((__turbopack_context__) => {
"use strict";

var { g: global, __dirname } = __turbopack_context__;
{
__turbopack_context__.s({
    "AdminSettings": (()=>AdminSettings),
    "Referral": (()=>Referral),
    "ReferralDeposit": (()=>ReferralDeposit),
    "User": (()=>User)
});
var __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/mongoose [external] (mongoose, cjs)");
var __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$bcryptjs$2f$index$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/node_modules/bcryptjs/index.js [app-route] (ecmascript)");
;
;
const authenticatorSchema = new __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["Schema"]({
    credentialID: {
        type: Buffer,
        required: true
    },
    credentialPublicKey: {
        type: Buffer,
        required: true
    },
    counter: {
        type: Number,
        required: true
    },
    transports: {
        type: [
            String
        ]
    }
});
const referralSchema = new __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["Schema"]({
    referrerId: {
        type: __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].Schema.Types.ObjectId,
        ref: "User"
    },
    referredId: {
        type: __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].Schema.Types.ObjectId,
        ref: "User"
    }
}, {
    timestamps: true
});
const referralDepositSchema = new __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["Schema"]({
    referredId: {
        type: __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].Schema.Types.ObjectId,
        ref: "User"
    },
    amount: {
        type: Number
    },
    referrerCredit: {
        type: Number
    }
}, {
    timestamps: true
});
const reservedAccountDetailsSchema = new __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["Schema"]({
    accountName: {
        type: String,
        default: ""
    },
    accountReferences: {
        type: String,
        default: ""
    },
    reservationReference: {
        type: String,
        default: ""
    },
    accounts: [
        {
            bankCode: {
                type: String,
                default: ""
            },
            bankName: {
                type: String,
                default: ""
            },
            accountNumber: {
                type: String,
                default: ""
            },
            accountName: {
                type: String,
                default: ""
            }
        }
    ]
});
// const webAuthCredentialSchema = new Schema<WebAuthCredential>({
//   credentialID: { type: String, required: true }, // Base64URL
//   credentialPublicKey: { type: String, required: true }, // Base64URL
//   transports: { type: [String], default: [] },
//   counter: { type: Number, required: true },
// });
const userSchema = new __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["Schema"]({
    username: {
        type: String,
        unique: true
    },
    firstName: {
        type: String
    },
    middleName: {
        type: String
    },
    lastName: {
        type: String
    },
    name: {
        type: String
    },
    email: {
        type: String,
        unique: true
    },
    role: {
        type: String,
        enum: [
            "admin",
            "user"
        ]
    },
    userType: {
        type: String,
        enum: [
            "Smart Earner",
            "TopUser",
            "API User",
            "Affiliate User"
        ],
        default: "Smart Earner"
    },
    mobileNumber: {
        type: String
    },
    accountBalance: {
        type: Number,
        default: 0
    },
    reservedAccountDetails: [
        reservedAccountDetailsSchema
    ],
    bvn: {
        type: String
    },
    nin: {
        type: String
    },
    image: {
        type: String,
        default: ""
    },
    dateOfBirth: {
        type: Date
    },
    transactionPin: {
        type: String
    },
    referralCode: {
        type: String,
        unique: true
    },
    referredBy: [
        {
            type: __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].Schema.Types.ObjectId,
            ref: "User",
            default: []
        }
    ],
    refererBonus: {
        type: Number,
        default: 0
    },
    thumbprintStatus: {
        type: Boolean,
        default: false
    },
    transactionStatus: {
        type: Boolean,
        default: false
    },
    lastLogin: {
        type: Date,
        default: null
    },
    dateJoined: {
        type: Date,
        default: Date.now
    },
    webhookUrl: {
        type: String
    },
    currentChallenge: {
        type: String
    },
    authenticators: [
        authenticatorSchema
    ],
    hasSeenModal: {
        type: Boolean,
        default: false
    },
    hasTransactionPin: {
        type: Boolean,
        default: false
    },
    transactionPinResetCode: {
        type: Number
    },
    transactionPinResetExpires: {
        type: Date
    },
    failedResetAttempts: {
        type: Number,
        default: 0
    }
}, {
    timestamps: true,
    toJSON: {
        virtuals: true
    },
    toObject: {
        virtuals: true
    }
});
const adminSettingsSchema = new __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["Schema"]({
    firstDepositPercentage: {
        type: Number,
        default: 1.5
    },
    subsequentDepositPercentage: {
        type: Number,
        default: 0.5
    },
    depositFeePercentage: {
        type: Number,
        default: 1.5
    }
});
userSchema.pre("save", async function(next) {
    if (this.isModified("transactionPin")) {
        const salt = await __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$bcryptjs$2f$index$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"].genSalt(10);
        this.transactionPin = await __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$bcryptjs$2f$index$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"].hash(this.transactionPin, salt);
    }
    next();
});
userSchema.virtual("referrals", {
    ref: "Referral",
    localField: "_id",
    foreignField: "referrerId"
});
const User = __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].models.User || (0, __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["model"])("User", userSchema);
const Referral = __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].models.Referral || (0, __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["model"])("Referral", referralSchema);
const ReferralDeposit = __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].models.ReferralDeposit || (0, __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["model"])("ReferralDeposit", referralDepositSchema);
const AdminSettings = __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].models.AdminSettings || (0, __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["model"])("AdminSettings", adminSettingsSchema);
}}),
"[project]/models/transactions.ts [app-route] (ecmascript)": ((__turbopack_context__) => {
"use strict";

var { g: global, __dirname } = __turbopack_context__;
{
__turbopack_context__.s({
    "default": (()=>__TURBOPACK__default__export__)
});
var __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/mongoose [external] (mongoose, cjs)");
;
const transactionSchema = new __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["Schema"]({
    type: {
        type: String,
        required: true,
        enum: [
            "CableSubscription",
            "BillPayment",
            "ManualFunding",
            "AutomaticFunding",
            "DataTransaction",
            "AirtimeTransaction",
            "WithdrawalTransaction",
            "ReferalBonus",
            "RefundTransaction"
        ]
    },
    amount: {
        type: Number
    },
    balanceBefore: {
        type: Number
    },
    balanceAfter: {
        type: Number
    },
    adminEmail: {
        type: String
    },
    status: {
        type: String,
        required: true,
        enum: [
            "Pending",
            "Successful",
            "Failed"
        ]
    },
    referenceId: {
        type: String,
        unique: true
    },
    // Airtime Subscription Field
    airtimeType: {
        type: String
    },
    buyingPrice: {
        type: Number
    },
    // Cable Subscription Fields
    iucOrSmartcardNumber: {
        type: Number
    },
    request_id: {
        type: String
    },
    provider: {
        type: String
    },
    cablePlan: {
        type: String
    },
    action: {
        type: String
    },
    userId: {
        type: String
    },
    userEmail: {
        type: String
    },
    refund: {
        type: Boolean,
        default: false
    },
    bypass: {
        type: Boolean,
        default: false
    },
    // Bill Payment Fields
    meterNumber: {
        type: Number
    },
    token: {
        type: String
    },
    customerPhone: {
        type: Number
    },
    meterType: {
        type: String
    },
    customerName: {
        type: String
    },
    customerAddress: {
        type: String
    },
    discoName: {
        type: String
    },
    // Data Transaction Fields
    planType: {
        type: String
    },
    mobileNumber: {
        type: Number
    },
    medium: {
        type: String
    },
    network: {
        type: String
    },
    plansize: {
        type: String
    },
    // Funding Transaction Fields
    fundingType: {
        type: String,
        enum: [
            "Manual",
            "Automatic"
        ]
    },
    fundingSource: {
        type: String,
        enum: [
            "API",
            "Admin",
            "Referral",
            "ONE TIME PAYMENT"
        ]
    }
}, {
    timestamps: true
});
// Create the model if it doesn't already exist
const Transaction = __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].models.Transaction || (0, __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["model"])("Transaction", transactionSchema);
const __TURBOPACK__default__export__ = Transaction;
}}),
"[project]/lib/connectdb.ts [app-route] (ecmascript)": ((__turbopack_context__) => {
"use strict";

var { g: global, __dirname } = __turbopack_context__;
{
__turbopack_context__.s({
    "default": (()=>__TURBOPACK__default__export__)
});
var __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/mongoose [external] (mongoose, cjs)");
;
const MONGODB_URI = process.env.MONGODB_URI;
let isConnected = false;
const dbConnect = async ()=>{
    __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].set("strictQuery", true);
    if (isConnected) {
        return;
    }
    try {
        await __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].connect(MONGODB_URI, {
            dbName: "VTUAPP"
        });
        isConnected = true;
    } catch (error) {
        throw error;
    }
};
const __TURBOPACK__default__export__ = dbConnect;
}}),
"[project]/models/notification.ts [app-route] (ecmascript)": ((__turbopack_context__) => {
"use strict";

var { g: global, __dirname } = __turbopack_context__;
{
__turbopack_context__.s({
    "deleteNotification": (()=>deleteNotification),
    "getAllNotifications": (()=>getAllNotifications),
    "getAllUsers": (()=>getAllUsers),
    "getNotification": (()=>getNotification),
    "getUserNotifications": (()=>getUserNotifications),
    "saveNotification": (()=>saveNotification),
    "updateNotification": (()=>updateNotification)
});
var __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/mongoose [external] (mongoose, cjs)");
var __TURBOPACK__imported__module__$5b$project$5d2f$lib$2f$connectdb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/lib/connectdb.ts [app-route] (ecmascript)");
var __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$user$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/models/user.ts [app-route] (ecmascript)");
;
;
;
const NotificationSchema = new __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["Schema"]({
    message: {
        type: String,
        required: true
    },
    recipient: {
        type: String,
        required: true
    },
    createdAt: {
        type: Date,
        default: Date.now
    }
});
const Notification = __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].models.Notification || __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].model("Notification", NotificationSchema);
async function saveNotification(message, recipient) {
    await (0, __TURBOPACK__imported__module__$5b$project$5d2f$lib$2f$connectdb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"])();
    const notification = new Notification({
        message,
        recipient
    });
    await notification.save();
}
async function getUserNotifications(email) {
    await (0, __TURBOPACK__imported__module__$5b$project$5d2f$lib$2f$connectdb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"])();
    return Notification.find({
        $or: [
            {
                recipient: email
            },
            {
                recipient: "all"
            }
        ]
    }).sort({
        createdAt: -1
    });
}
async function getAllNotifications() {
    await (0, __TURBOPACK__imported__module__$5b$project$5d2f$lib$2f$connectdb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"])();
    return Notification.find().sort({
        createdAt: -1
    });
}
async function getAllUsers() {
    await (0, __TURBOPACK__imported__module__$5b$project$5d2f$lib$2f$connectdb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"])();
    return __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$user$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["User"].find().select("email -_id");
}
async function getNotification(id) {
    await (0, __TURBOPACK__imported__module__$5b$project$5d2f$lib$2f$connectdb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"])();
    return Notification.findById(id);
}
async function updateNotification(id, message, recipient) {
    await (0, __TURBOPACK__imported__module__$5b$project$5d2f$lib$2f$connectdb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"])();
    return Notification.findByIdAndUpdate(id, {
        message,
        recipient
    }, {
        new: true
    });
}
async function deleteNotification(id) {
    await (0, __TURBOPACK__imported__module__$5b$project$5d2f$lib$2f$connectdb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"])();
    return Notification.findByIdAndDelete(id);
}
}}),
"[externals]/util [external] (util, cjs)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
const mod = __turbopack_context__.x("util", () => require("util"));

module.exports = mod;
}}),
"[externals]/url [external] (url, cjs)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
const mod = __turbopack_context__.x("url", () => require("url"));

module.exports = mod;
}}),
"[externals]/http [external] (http, cjs)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
const mod = __turbopack_context__.x("http", () => require("http"));

module.exports = mod;
}}),
"[externals]/assert [external] (assert, cjs)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
const mod = __turbopack_context__.x("assert", () => require("assert"));

module.exports = mod;
}}),
"[externals]/querystring [external] (querystring, cjs)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
const mod = __turbopack_context__.x("querystring", () => require("querystring"));

module.exports = mod;
}}),
"[externals]/buffer [external] (buffer, cjs)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
const mod = __turbopack_context__.x("buffer", () => require("buffer"));

module.exports = mod;
}}),
"[externals]/zlib [external] (zlib, cjs)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
const mod = __turbopack_context__.x("zlib", () => require("zlib"));

module.exports = mod;
}}),
"[externals]/https [external] (https, cjs)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
const mod = __turbopack_context__.x("https", () => require("https"));

module.exports = mod;
}}),
"[externals]/events [external] (events, cjs)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
const mod = __turbopack_context__.x("events", () => require("events"));

module.exports = mod;
}}),
"[project]/app/api/adminapi/wallet/withdraw/route.ts [app-route] (ecmascript)": ((__turbopack_context__) => {
"use strict";

var { g: global, __dirname } = __turbopack_context__;
{
// app/api/adminapi/wallet/withdraw/route.ts
__turbopack_context__.s({
    "POST": (()=>POST)
});
var __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/node_modules/next/server.js [app-route] (ecmascript)");
var __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$user$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/models/user.ts [app-route] (ecmascript)");
var __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$transactions$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/models/transactions.ts [app-route] (ecmascript)");
var __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$notification$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/models/notification.ts [app-route] (ecmascript)");
var __TURBOPACK__imported__module__$5b$project$5d2f$lib$2f$connectdb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/lib/connectdb.ts [app-route] (ecmascript)");
var __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2d$auth$2f$index$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/node_modules/next-auth/index.js [app-route] (ecmascript)");
;
;
;
;
;
;
async function POST(req) {
    try {
        await (0, __TURBOPACK__imported__module__$5b$project$5d2f$lib$2f$connectdb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"])();
        const { userId, amount, description } = await req.json();
        // Validate input
        if (!userId || !amount || amount <= 0) {
            return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
                message: "Invalid request parameters"
            }, {
                status: 400
            });
        }
        // Get admin from session (replace with your actual auth system)
        const session = await (0, __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2d$auth$2f$index$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["getServerSession"])();
        const admin = await __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$user$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["User"].findOne({
            $or: [
                {
                    _id: session?.user?.id
                },
                {
                    email: session?.user?.email
                }
            ],
            role: "admin"
        });
        if (!admin) {
            return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
                message: "Admin authentication required"
            }, {
                status: 401
            });
        }
        // Check user and balance
        const user = await __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$user$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["User"].findById(userId);
        if (!user) {
            return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
                message: "If the user exists, they will be handled accordingly."
            }, {
                status: 404
            });
        }
        if (user.accountBalance < amount && amount > 0) {
            return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
                message: "Insufficient wallet balance"
            }, {
                status: 400
            });
        }
        // Process withdrawal
        const balanceBefore = user.accountBalance;
        const balanceAfter = balanceBefore - amount;
        user.accountBalance = balanceAfter;
        await user.save();
        // Create transaction record
        const transaction = new __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$transactions$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"]({
            type: "WithdrawalTransaction",
            amount,
            balanceBefore,
            balanceAfter,
            userEmail: user.email,
            adminEmail: admin.email,
            status: "Successful",
            userId,
            referenceId: `WITHDRAW-${Date.now()}-${Math.floor(Math.random() * 1000)}`
        });
        await transaction.save();
        // Send notification
        await (0, __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$notification$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["saveNotification"])(`₦${amount.toFixed(2)} has been withdrawn from your wallet. New balance: ₦${balanceAfter.toFixed(2)} the reason for the transaction is because ${description}`, user.email);
        return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
            message: "Withdrawal successful",
            transaction: {
                _id: transaction._id,
                type: transaction.type,
                amount: transaction.amount,
                balanceBefore: transaction.balanceBefore,
                balanceAfter: transaction.balanceAfter,
                status: transaction.status,
                userId: transaction.userId,
                referenceId: transaction.referenceId,
                createdAt: transaction.createdAt
            },
            newBalance: balanceAfter
        });
    } catch (error) {
        console.error("Withdraw funds error:", error);
        return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
            message: "Failed to withdraw funds",
            error: typeof error === "object" && error !== null && "message" in error ? error.message : String(error)
        }, {
            status: 500
        });
    }
}
}}),

};

//# sourceMappingURL=%5Broot-of-the-server%5D__3522913b._.js.map