import psutil
import platform
import math
import cpuinfo
from Controller import mysql_connect

def get_cpu_info():
    return cpuinfo.get_cpu_info()['brand_raw']

def get_cpu_sql():
    query = f"SELECT `Prozessor-Anzahl` FROM `CPU-Liste` WHERE `CPU-Name`='{cpuinfo.get_cpu_info()['brand_raw']}'"
    return mysql_connect.get_cpu(query,"Stines-GmbH",cpuinfo.get_cpu_info()['brand_raw'])

def get_ram_info():
    ram_info = psutil.virtual_memory()
    total_ram = ram_info.total / (1024 ** 3)  # In Gigabytes
    return math.ceil(total_ram)

def get_hdd_info():
    total_disk_size = 0
    disk_partitions = psutil.disk_partitions()
    for partition in disk_partitions:
    # Wenn du das Laufwerk C: ignorieren möchtest
        if partition.device != 'C:\\':
            partition_info = psutil.disk_usage(partition.mountpoint)
            total_disk_size += partition_info.total / (1024 ** 3)
    return math.ceil(total_disk_size)

# Informationen über die CPU
def set_system_info(name,ipadress):
    query = f"UPDATE `Kunden-Server` SET RAM={get_ram_info()}, Prozessor={get_cpu_sql()[0]}, CPU='{get_cpu_info()}' WHERE `IP-Adresse`='{ipadress}'"
    return mysql_connect.update_cpu(query,"Stines-GmbH",get_cpu_sql()[0])