#!/usr/bin/env python3
"""
Script to update subscription plan prices in the database
"""

from app import app
from models import db, SubscriptionPlan
from decimal import Decimal

def update_plan_prices():
    """Update the prices for Pro and Enterprise plans"""

    with app.app_context():
        # Update Pro Plan price to $150
        pro_plan = SubscriptionPlan.query.filter_by(name='pro').first()
        if pro_plan:
            old_price = pro_plan.price
            pro_plan.price = Decimal('150.00')
            print(f"Updated Pro Plan price from ${old_price} to $150.00")
        else:
            print("Pro Plan not found in database")

        # Update Enterprise Plan price to $349
        enterprise_plan = SubscriptionPlan.query.filter_by(name='enterprise').first()
        if enterprise_plan:
            old_price = enterprise_plan.price
            enterprise_plan.price = Decimal('349.00')
            print(f"Updated Enterprise Plan price from ${old_price} to $349.00")
        else:
            print("Enterprise Plan not found in database")

        # Commit the changes
        try:
            db.session.commit()
            print("\nPrices updated successfully!")

            # Display all plans
            print("\nCurrent subscription plans:")
            plans = SubscriptionPlan.query.filter_by(is_active=True).order_by(SubscriptionPlan.price).all()
            for plan in plans:
                print(f"  - {plan.display_name}: ${plan.price}")

        except Exception as e:
            db.session.rollback()
            print(f"Error updating prices: {str(e)}")
            return False

    return True

if __name__ == "__main__":
    update_plan_prices()