const prisma = require('../../../src/prisma/PrismaClient.js');
const timeLocal = require('../../../src/utils/TimeLocal.js')

const cityNames = [
    'Kabupaten Badung',
    'Kabupaten Bangli',
    'Kabupaten Buleleng',
    'Kabupaten Gianyar',
    'Kabupaten Jembrana',
    'Kabupaten Karangasem',
    'Kabupaten Klungkung',
    'Kabupaten Tabanan',
    'Kota Denpasar'

    // 9
];

exports.seedBaliCities = async () => {
    const province = await prisma.province.findFirst({
        where: { name: 'Bali' },
    });

    if (!province) {
        console.error('❌ Province Bali not found. Seed it first.');
        return;
    }

    for (const name of cityNames) {
        await prisma.city.upsert({
            where: {
                name_province_id: {
                    name,
                    province_id: province.id,
                },
            },
            update: {
                updatedAt: timeLocal.now().toDate()
            },
            create: {
                name,
                province_id: province.id,
                createdAt: timeLocal.now().toDate()
            },
        });
    }

    console.log('✅ Bali City seeded!.');
};