#!/usr/bin/env python3
"""Reset database with new schema including product variants"""

import os
from app import app, db

def reset_database():
    with app.app_context():
        # Drop all tables
        db.drop_all()
        print("Dropped all tables")
        
        # Create all tables with new schema
        db.create_all()
        print("Created all tables with new schema")
        
        # Initialize basic data
        from models import Category, Subcategory, Admin
        
        # Create categories
        categories = [
            Category(name='Clothes'),
            Category(name='Cosmetics'),
            Category(name='Accessories')
        ]
        
        for category in categories:
            db.session.add(category)
        
        db.session.commit()
        
        # Create subcategories
        subcategories = [
            Subcategory(name='Tops', category_id=1),
            Subcategory(name='Bottoms', category_id=1),
            Subcategory(name='Dresses', category_id=1),
            Subcategory(name='Makeup', category_id=2),
            Subcategory(name='Skincare', category_id=2),
            Subcategory(name='Fragrance', category_id=2),
        ]
        
        for subcategory in subcategories:
            db.session.add(subcategory)
        
        # Create admin user
        admin = Admin(username='admin', email='admin@gaz.com')
        admin.set_password('@sisiafashionhouse30')
        db.session.add(admin)
        
        db.session.commit()
        print("Database reset and initialized successfully!")

if __name__ == "__main__":
    reset_database()