import { PrismaClient, BillingType, PlanInterval, RegionCode } from "@prisma/client";
import * as bcrypt from "bcrypt";

const prisma = new PrismaClient();

async function main() {
    const commonFeatures = [
        "Unlimited AI conversation",
        "AI pronunciation scoring",
        "Speaking practice",
        "Full CBT exam bank",
        "Mock exams",
        "Advanced grammar lessons",
        "AI writing correction",
        "AI study plans"
    ];

    const plansData = [
        {
            name: "Premium Lifetime",
            billingType: BillingType.ONE_TIME,
            interval: PlanInterval.YEARLY, // Or omit if not required by your frontend logic
            displayOrder: 4,
            isPopular: false,
            badge: "Lifetime Offer",
            description: "Pay once, own forever.",
            features: commonFeatures,
            trialDays: 0,
            prices: {
                create: [
                    { countryCode: RegionCode.NG, currency: "NGN", price: 5900 * 100 },
                    { countryCode: RegionCode.ROW, currency: "GBP", price: 10 * 100 }
                ]
            },
            mappings: {
                create: [
                    { providerProductId: "lifetime" }
                ]
            }
        },
        {
            name: "Premium Monthly",
            billingType: BillingType.RECURRING,
            interval: PlanInterval.MONTHLY,
            displayOrder: 2,
            isPopular: true,
            badge: "Most Popular",
            description: "Everything to master English.",
            features: commonFeatures,
            trialDays: 7,
            prices: {
                create: [
                    { countryCode: RegionCode.NG, currency: "NGN", price: 1200 * 100 },
                    { countryCode: RegionCode.ROW, currency: "GBP", price: 10 * 100 }
                ]
            },
            mappings: {
                create: [
                    { providerProductId: "monthly" }
                ]
            }
        },
        {
            name: "Premium Weekly",
            billingType: BillingType.RECURRING,
            interval: PlanInterval.WEEKLY,
            displayOrder: 1,
            isPopular: false,
            badge: "",
            description: "Short-term access.",
            features: commonFeatures,
            trialDays: 0,
            prices: {
                create: [
                    { countryCode: RegionCode.NG, currency: "NGN", price: 500 * 100 },
                    { countryCode: RegionCode.ROW, currency: "GBP", price: 10 * 100 }
                ]
            },
            mappings: {
                create: [
                    { providerProductId: "weekly" }
                ]
            }
        },
        {
            name: "Premium Yearly",
            billingType: BillingType.RECURRING,
            interval: PlanInterval.YEARLY,
            displayOrder: 3,
            isPopular: false,
            badge: "Best value",
            description: "Best value subscription.",
            features: commonFeatures,
            trialDays: 7,
            prices: {
                create: [
                    { countryCode: RegionCode.NG, currency: "NGN", price: 2500 * 100 },
                    { countryCode: RegionCode.ROW, currency: "GBP", price: 10 * 100 }
                ]
            },
            mappings: {
                create: [
                    { providerProductId: "yearly" }
                ]
            }
        }
    ];

    for (const planData of plansData) {
        const plan = await prisma.subscriptionPlan.create({
            data: planData
        });
        console.log("Created plan:", plan.name);
    }

    console.log("Seed completed.");
}

main().catch(console.error).finally(() => prisma.$disconnect());