"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const client_1 = require("@prisma/client");
const prisma = new client_1.PrismaClient();
async function main() {
    const estate = await prisma.estate.upsert({
        where: { id: '00000000-0000-4000-8000-000000000001' },
        update: {
            subscriptionPlanId: '00000000-0000-4000-8000-000000000102',
            settings: demoEstateSettings()
        },
        create: {
            id: '00000000-0000-4000-8000-000000000001',
            name: 'GreenPark Estate',
            location: 'Lagos, Nigeria',
            unitCount: 120,
            estateType: 'Residential gated community',
            status: client_1.EstateStatus.ACTIVE,
            signupStatus: client_1.EstateSignupStatus.APPROVED,
            subscriptionStatus: client_1.SubscriptionStatus.ACTIVE,
            subscriptionPlanId: '00000000-0000-4000-8000-000000000102',
            activatedAt: new Date(),
            settings: demoEstateSettings(),
            branding: {
                primaryColor: '#0f766e'
            }
        }
    });
    await prisma.user.upsert({
        where: { phone: '+2348000000001' },
        update: {},
        create: {
            estateId: null,
            phone: '+2348000000001',
            name: 'Ade Okafor',
            firstName: 'Ade',
            lastName: 'Okafor',
            role: client_1.UserRole.SUPER_ADMIN
        }
    });
    const salesAdmin = await prisma.user.upsert({
        where: { phone: '+2348000000005' },
        update: {},
        create: {
            estateId: null,
            phone: '+2348000000005',
            name: 'Ade Okafor',
            firstName: 'Ade',
            lastName: 'Okafor',
            role: client_1.UserRole.SALES_ADMIN
        }
    });
    await prisma.salesPartnerProfile.upsert({
        where: { salesAdminId: salesAdmin.id },
        update: {},
        create: {
            salesAdminId: salesAdmin.id,
            enabled: false,
            notes: 'Partner earnings disabled by default.'
        }
    });
    const admin = await prisma.user.upsert({
        where: { phone: '+2348000000002' },
        update: {},
        create: {
            estateId: estate.id,
            phone: '+2348000000002',
            name: 'Ade Okafor',
            firstName: 'Ade',
            lastName: 'Okafor',
            role: client_1.UserRole.ESTATE_ADMIN
        }
    });
    const residentUser = await prisma.user.upsert({
        where: { phone: '+2348000000003' },
        update: {
            name: 'Ade Okafor',
            firstName: 'Ade',
            lastName: 'Okafor',
            profileCompletion: 100,
            profileConfirmed: true
        },
        create: {
            estateId: estate.id,
            phone: '+2348000000003',
            name: 'Ade Okafor',
            firstName: 'Ade',
            lastName: 'Okafor',
            profileCompletion: 100,
            profileConfirmed: true,
            role: client_1.UserRole.RESIDENT
        }
    });
    await prisma.resident.upsert({
        where: { userId: residentUser.id },
        update: {
            name: 'Ade Okafor',
            firstName: 'Ade',
            lastName: 'Okafor'
        },
        create: {
            estateId: estate.id,
            userId: residentUser.id,
            residentCode: 'RES-SEED000001',
            name: 'Ade Okafor',
            firstName: 'Ade',
            lastName: 'Okafor',
            phone: '+2348000000003',
            unit: 'A12',
            blockNumber: 'Block A',
            flatNumber: 'A12',
            address: 'Block A, Flat A12, GreenPark Estate',
            profileCompletion: 100,
            profileConfirmed: true
        }
    });
    const mainGate = await prisma.estateGate.upsert({
        where: { estateId_name: { estateId: estate.id, name: 'Main Gate' } },
        update: {},
        create: {
            estateId: estate.id,
            name: 'Main Gate',
            type: client_1.EstateGateType.MAIN,
            description: 'Default main gate'
        }
    });
    const guardUser = await prisma.user.upsert({
        where: { phone: '+2348000000004' },
        update: {
            name: 'Ade Okafor',
            firstName: 'Ade',
            lastName: 'Okafor',
            profileCompletion: 100,
            profileConfirmed: true
        },
        create: {
            estateId: estate.id,
            phone: '+2348000000004',
            name: 'Ade Okafor',
            firstName: 'Ade',
            lastName: 'Okafor',
            profileCompletion: 100,
            profileConfirmed: true,
            role: client_1.UserRole.GUARD
        }
    });
    await prisma.guard.upsert({
        where: { userId: guardUser.id },
        update: {
            name: 'Ade Okafor',
            firstName: 'Ade',
            lastName: 'Okafor'
        },
        create: {
            estateId: estate.id,
            userId: guardUser.id,
            guardCode: 'GRD-SEED000001',
            name: 'Ade Okafor',
            firstName: 'Ade',
            lastName: 'Okafor',
            phone: '+2348000000004',
            address: 'Main security post',
            emergencyContact: { name: 'Supervisor', phone: '+2348000000002' },
            assignedGateId: mainGate.id,
            assignedShifts: [{ day: 'DAILY', startsAt: '08:00', endsAt: '18:00' }],
            profilePictureUrl: 'https://example.com/guard-profile.jpg',
            profileCompletion: 100,
            profileConfirmed: true,
            deviceId: 'guard-device-001'
        }
    });
    await prisma.auditLog.create({
        data: {
            estateId: estate.id,
            actorType: 'USER',
            actorId: admin.id,
            action: 'SEED_DATA_CREATED',
            metadata: { estateId: estate.id }
        }
    });
}
main()
    .finally(async () => {
    await prisma.$disconnect();
})
    .catch(async (error) => {
    console.error(error);
    await prisma.$disconnect();
    process.exit(1);
});
function demoEstateSettings() {
    return {
        timezone: 'Africa/Lagos',
        gates: ['Main Gate'],
        profileRequirements: {
            resident: {
                requiredFields: ['firstName', 'lastName', 'phone', 'blockNumber', 'flatNumber', 'address', 'estateId', 'profileConfirmed'],
                usesBlocks: true,
                usesFlats: true
            },
            guard: {
                requiredFields: [
                    'firstName',
                    'lastName',
                    'phone',
                    'guardCode',
                    'assignedGateId',
                    'assignedShifts',
                    'profilePictureUrl',
                    'address',
                    'emergencyContact',
                    'estateId',
                    'profileConfirmed'
                ]
            }
        },
        announcements: {
            allowedCategories: ['SECURITY', 'MAINTENANCE', 'NEWS', 'EVENTS', 'NOTICES', 'EMERGENCY'],
            dailyPostingLimit: 10,
            approvalRequiredForFlaggedKeywords: true
        },
        demoAccess: {
            approved: true,
            maxSessionMinutes: 120,
            expiresAt: new Date(Date.now() + 1000 * 60 * 60 * 24 * 14).toISOString()
        }
    };
}
//# sourceMappingURL=seed.js.map