import { EntityManager } from '@mikro-orm/core';
import { UserRole } from '@/apps/_app/entities/user/UserRole';
import { PLATFORMROLES } from '@/constants/roles';

export class RoleSeed {
    constructor(private readonly em: EntityManager) {}

    async run() {
        console.log('Seeding roles...');

        const roles = Object.values(PLATFORMROLES);
        
        for (const roleName of roles) {
            const existingRole = await this.em.findOne(UserRole, { name: roleName });
            
            if (!existingRole) {
                const role = new UserRole();
                role.name = roleName;
                await this.em.persistAndFlush(role);
                console.log(`Created role: ${roleName}`);
            }
        }

        console.log('Role seeding completed!');
    }
} 