from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from models.models import Client
from dotenv import load_dotenv
import os
from datetime import datetime, timedelta
import random
import uuid

# .env laden
load_dotenv()

DB_USER = os.getenv("DB_USER")
DB_PASSWORD = os.getenv("DB_PASSWORD")
DB_HOST = os.getenv("DB_HOST")
DB_NAME = os.getenv("DB_NAME")

db_conn_str = f"mysql+pymysql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}/{DB_NAME}"
engine = create_engine(db_conn_str)
Session = sessionmaker(bind=engine)
session = Session()

# Dummy-Clients erzeugen
locations = [
    "Raum 101",
    "Raum 102",
    "Lehrerzimmer",
    "Aula",
    "Bibliothek"
]

for i in range(5):
    client = Client(
        uuid=str(uuid.uuid4()),
        hardware_hash=f"dummyhash{i:02d}",
        location=locations[i],
        ip_address=f"192.168.0.{100+i}",
        registration_time=datetime.now() - timedelta(days=random.randint(1, 30)),
        last_alive=datetime.now(),
        is_active=True
    )
    session.add(client)

session.commit()
print("5 Dummy-Clients wurden angelegt.")
