from functions.database import get_db_connection, Usuario, Role
from werkzeug.security import generate_password_hash

def create_test_users():
    """Cria usuários de teste"""
    db = get_db_connection()
    try:
        # Lista de usuários de teste
        test_users = [
            {
                'username': 'aligner',
                'email': 'aligner@test.com',
                'password': 'Test123!@#',
                'is_admin': False
            },
            {
                'username': 'tester',
                'email': 'tester@test.com', 
                'password': 'Test123!@#',
                'is_admin': False
            },
            {
                'username': 'deployer',
                'email': 'deployer@test.com',
                'password': 'Test123!@#',
                'is_admin': False
            }
        ]

        # Criar cada usuário
        for user_data in test_users:
            user = db.query(Usuario).filter_by(username=user_data['username']).first()
            
            if not user:
                user = Usuario(
                    username=user_data['username'],
                    email=user_data['email'],
                    is_admin=user_data['is_admin']
                )
                user.set_password(user_data['password'])
                db.add(user)
                print(f"Usuário {user_data['username']} criado")
            else:
                print(f"Usuário {user_data['username']} já existe")

        db.commit()
        print("Usuários de teste criados com sucesso")

    except Exception as e:
        print(f"Erro ao criar usuários de teste: {str(e)}")
        db.rollback()
    finally:
        db.close()

if __name__ == "__main__":
    create_test_users() 