import os
import django

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
django.setup()

from shop.models import ESP32Config

def populate():
    # 检查数据库是否已有数据，如果有则跳过，避免每次构建都重置
    if ESP32Config.objects.exists():
        print("ESP32Config data already exists, skipping population.")
        return

    # 清除旧数据，避免重复累积
    # 注意：在生产环境中慎用 delete
    # ESP32Config.objects.all().delete()
    
    configs = [
        {
            "name": "AI小智 Mini款",
            "chip_type": "ESP32-C3",
            "flash_size": 4,
            "ram_size": 1,
            "has_camera": False,
            "has_microphone": True,
            "price": 150.00,
            "description": "高性价比入门款，支持语音交互，小巧便携。"
        },
        {
            "name": "AI小智 V2款 (舵机版)",
            "chip_type": "ESP32-S3",
            "flash_size": 8,
            "ram_size": 2,
            "has_camera": False,
            "has_microphone": True,
            "price": 188.00,
            "description": "升级版性能，支持驱动舵机，适合机器人控制与运动交互。"
        },
        {
            "name": "AI小智 V3款 (视觉版)",
            "chip_type": "ESP32-S3",
            "flash_size": 16,
            "ram_size": 8,
            "has_camera": True,
            "has_microphone": True,
            "price": 250.00,
            "description": "旗舰视觉版，配备摄像头与高性能计算单元，支持视觉识别与复杂AI任务。"
        }
    ]

    for data in configs:
        config = ESP32Config.objects.create(**data)
        print(f"Created: {config.name} - ¥{config.price}")

if __name__ == '__main__':
    populate()
