module.exports = [
"[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)", ((__turbopack_context__, module, exports) => {

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/next-server/app-page-turbo.runtime.dev.js [external] (next/dist/compiled/next-server/app-page-turbo.runtime.dev.js, cjs)", ((__turbopack_context__, module, exports) => {

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)", ((__turbopack_context__, module, exports) => {

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)", ((__turbopack_context__, module, exports) => {

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/shared/lib/no-fallback-error.external.js [external] (next/dist/shared/lib/no-fallback-error.external.js, cjs)", ((__turbopack_context__, module, exports) => {

const mod = __turbopack_context__.x("next/dist/shared/lib/no-fallback-error.external.js", () => require("next/dist/shared/lib/no-fallback-error.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)", ((__turbopack_context__, module, exports) => {

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)", ((__turbopack_context__, module, exports) => {

const mod = __turbopack_context__.x("mongoose", () => require("mongoose"));

module.exports = mod;
}),
"[project]/Desktop/Aynnaka/DiffaTours-main 2/src/lib/mongodb.ts [app-route] (ecmascript)", ((__turbopack_context__) => {
"use strict";

__turbopack_context__.s([
    "connectDB",
    ()=>connectDB,
    "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)");
;
let cached = global.mongoose || {
    conn: null,
    promise: null
};
if (!global.mongoose) {
    global.mongoose = cached;
}
const MONGODB_URI = process.env.MONGODB_URI;
if (!MONGODB_URI) {
    throw new Error('Missing MONGODB_URI environment variable');
}
async function connectDB() {
    // Return existing connection if ready
    if (cached.conn?.connection.readyState === 1) {
        return cached.conn;
    }
    // Wait for pending connection
    if (cached.promise) {
        cached.conn = await cached.promise;
        return cached.conn;
    }
    // Create new connection with serverless-optimized settings
    // MONGODB_URI is guaranteed to be string here due to the check above
    cached.promise = __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].connect(MONGODB_URI, {
        bufferCommands: false,
        maxPoolSize: 1,
        minPoolSize: 0,
        serverSelectionTimeoutMS: 5000,
        socketTimeoutMS: 30000,
        heartbeatFrequencyMS: 10000,
        maxIdleTimeMS: 10000,
        waitQueueTimeoutMS: 5000
    });
    try {
        cached.conn = await cached.promise;
        console.log('MongoDB connected');
        return cached.conn;
    } catch (error) {
        cached.promise = null;
        console.error('MongoDB connection error:', error);
        throw error;
    }
}
const __TURBOPACK__default__export__ = connectDB;
}),
"[project]/Desktop/Aynnaka/DiffaTours-main 2/src/models/ExcursionCapacity.ts [app-route] (ecmascript)", ((__turbopack_context__) => {
"use strict";

__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 ExcursionCapacitySchema = new __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["Schema"]({
    excursionId: {
        type: String,
        required: true,
        index: true
    },
    date: {
        type: String,
        required: true,
        index: true
    },
    maxCapacity: {
        type: Number,
        required: true
    },
    currentBookings: {
        type: Number,
        required: true,
        default: 0
    },
    isAvailable: {
        type: Boolean,
        required: true,
        default: true
    },
    createdAt: {
        type: Date,
        default: Date.now
    },
    updatedAt: {
        type: Date,
        default: Date.now
    }
}, {
    collection: 'excursioncapacities'
});
// Compound index for unique excursion-date pairs
ExcursionCapacitySchema.index({
    excursionId: 1,
    date: 1
}, {
    unique: true
});
const __TURBOPACK__default__export__ = __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].models.ExcursionCapacity || __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].model('ExcursionCapacity', ExcursionCapacitySchema);
}),
"[project]/Desktop/Aynnaka/DiffaTours-main 2/src/app/api/capacity/check/route.ts [app-route] (ecmascript)", ((__turbopack_context__) => {
"use strict";

__turbopack_context__.s([
    "GET",
    ()=>GET
]);
var __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/Desktop/Aynnaka/DiffaTours-main 2/node_modules/next/server.js [app-route] (ecmascript)");
var __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$src$2f$lib$2f$mongodb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/Desktop/Aynnaka/DiffaTours-main 2/src/lib/mongodb.ts [app-route] (ecmascript)");
var __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$src$2f$models$2f$ExcursionCapacity$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/Desktop/Aynnaka/DiffaTours-main 2/src/models/ExcursionCapacity.ts [app-route] (ecmascript)");
;
;
;
async function GET(request) {
    try {
        await (0, __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$src$2f$lib$2f$mongodb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["connectDB"])();
        const { searchParams } = new URL(request.url);
        const excursionId = searchParams.get('excursion_id');
        const date = searchParams.get('date');
        const peopleCountStr = searchParams.get('people_count');
        // Validate required parameters
        if (!excursionId) {
            return __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
                error: 'excursion_id is required',
                code: 'MISSING_EXCURSION_ID'
            }, {
                status: 400
            });
        }
        if (!date) {
            return __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
                error: 'date is required',
                code: 'MISSING_DATE'
            }, {
                status: 400
            });
        }
        if (!peopleCountStr) {
            return __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
                error: 'people_count is required',
                code: 'MISSING_PEOPLE_COUNT'
            }, {
                status: 400
            });
        }
        // Validate excursion_id is non-empty
        if (excursionId.trim() === '') {
            return __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
                error: 'excursion_id must be a non-empty string',
                code: 'INVALID_EXCURSION_ID'
            }, {
                status: 400
            });
        }
        // Validate date format (YYYY-MM-DD)
        const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
        if (!dateRegex.test(date)) {
            return __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
                error: 'date must be in ISO format (YYYY-MM-DD)',
                code: 'INVALID_DATE_FORMAT'
            }, {
                status: 400
            });
        }
        // Validate date is a valid date
        const parsedDate = new Date(date);
        if (isNaN(parsedDate.getTime())) {
            return __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
                error: 'date must be a valid date',
                code: 'INVALID_DATE'
            }, {
                status: 400
            });
        }
        // Validate people_count is a positive integer
        const peopleCount = parseInt(peopleCountStr);
        if (isNaN(peopleCount) || peopleCount <= 0 || !Number.isInteger(peopleCount)) {
            return __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
                error: 'people_count must be a positive integer',
                code: 'INVALID_PEOPLE_COUNT'
            }, {
                status: 400
            });
        }
        // Query excursionCapacity collection for matching excursionId and date
        const capacity = await __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$src$2f$models$2f$ExcursionCapacity$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"].findOne({
            excursionId: excursionId,
            date: date
        });
        // If no capacity record exists, treat as unlimited/available
        if (!capacity) {
            return __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
                available: true,
                canBook: true,
                hasCapacityLimit: false,
                excursionId: excursionId,
                date: date,
                requestedPeople: peopleCount,
                message: 'No capacity limit set for this date'
            }, {
                status: 200
            });
        }
        // Capacity record exists, calculate availability
        const availableSpots = capacity.maxCapacity - capacity.currentBookings;
        const canBook = availableSpots >= peopleCount && capacity.isAvailable;
        // Determine availability status
        let availabilityStatus;
        if (availableSpots <= 0) {
            availabilityStatus = 'full';
        } else if (availableSpots < capacity.maxCapacity * 0.2) {
            availabilityStatus = 'limited';
        } else {
            availabilityStatus = 'available';
        }
        return __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
            available: capacity.isAvailable && availableSpots > 0,
            canBook: canBook,
            hasCapacityLimit: true,
            excursionId: excursionId,
            date: date,
            requestedPeople: peopleCount,
            maxCapacity: capacity.maxCapacity,
            currentBookings: capacity.currentBookings,
            availableSpots: availableSpots,
            isAvailable: capacity.isAvailable,
            availabilityStatus: availabilityStatus
        }, {
            status: 200
        });
    } catch (error) {
        console.error('GET error:', error);
        return __TURBOPACK__imported__module__$5b$project$5d2f$Desktop$2f$Aynnaka$2f$DiffaTours$2d$main__2$2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
            error: 'Internal server error: ' + (error instanceof Error ? error.message : 'Unknown error')
        }, {
            status: 500
        });
    }
}
}),
];

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