import csv

def update_user_profile(user_data, profile_wifi_ssid):
    """
    更新Users.csv文件中的用户配置文件信息。
    参数：
        user_data:一个包含用户配置文件数据的字典
        profile_wifi_ssid:要更新的用户的Wifi_SSID
    """
    with open('data/Users.csv', "r", encoding="utf-8") as file:
        csv_reader = csv.DictReader(file, delimiter=",")
        rows = [row for row in csv_reader]

    for row in rows:
        if row['Wifi_SSID'] == profile_wifi_ssid:
            row['User'] = user_data['User']
            row['User_pass'] = user_data['User_pass']
            row['Wifi_SSID'] = user_data['Wifi_SSID']
            row['Modbus_IP'] = user_data['Modbus_IP']
            row['Modbus_Port'] = user_data['Modbus_Port']
            row['NFC_ID'] = user_data['NFC_ID'] 
            row['Reserve'] = user_data['Reserve'] 
            break

    with open('data/Users.csv', newline="", mode="w", encoding="utf-8") as file:
        header = ["User", "User_pass", "Wifi_SSID", "Modbus_IP", "Modbus_Port", "NFC_ID", "Reserve"]
        csv_writer = csv.DictWriter(file, fieldnames=header)
        csv_writer.writeheader()
        csv_writer.writerows(rows)