#!/usr/bin/env python3
"""Script to add multiple color variants to the product"""

from app import app, db
from models import Product, ProductVariant

def add_color_variants():
    with app.app_context():
        # Get the product
        product = Product.query.first()
        if not product:
            print("No product found!")
            return
        
        print(f"Adding color variants to: {product.name}")
        
        # Define color variants
        colors = [
            {'name': 'Red', 'code': '#FF0000', 'stock': 10},
            {'name': 'Blue', 'code': '#0000FF', 'stock': 10},
            {'name': 'Green', 'code': '#008000', 'stock': 10},
            {'name': 'Black', 'code': '#000000', 'stock': 10},
            {'name': 'White', 'code': '#FFFFFF', 'stock': 10},
        ]
        
        # Check existing variants
        existing_colors = [v.color for v in product.variants]
        
        for color_data in colors:
            if color_data['name'] not in existing_colors:
                variant = ProductVariant(
                    product_id=product.id,
                    color=color_data['name'],
                    color_code=color_data['code'],
                    stock_quantity=color_data['stock'],
                    price_adjustment=0.0
                )
                db.session.add(variant)
                print(f"Added {color_data['name']} variant")
            else:
                print(f"{color_data['name']} variant already exists")
        
        db.session.commit()
        print("Color variants added successfully!")

if __name__ == "__main__":
    add_color_variants()
