"""
Management command to create or update the Free Trial plan
"""
from django.core.management.base import BaseCommand
from igny8_core.auth.models import Plan


class Command(BaseCommand):
    help = 'Create or update the Free Trial plan for signup'

    def handle(self, *args, **options):
        self.stdout.write('Creating/updating Free Trial plan...')
        
        plan, created = Plan.objects.update_or_create(
            slug='free-trial',
            defaults={
                'name': 'Free Trial',
                'price': 0.00,
                'billing_cycle': 'monthly',
                'included_credits': 2000,  # 2000 credits for trial
                'credits_per_month': 2000,  # Legacy field
                'max_sites': 1,
                'max_users': 1,
                'max_industries': 3,  # 3 sectors per site
                'max_author_profiles': 2,
                'is_active': True,
                'features': ['ai_writer', 'planner', 'basic_support'],
                'allow_credit_topup': False,  # No top-up during trial
                'extra_credit_price': 0.00,
            }
        )
        
        if created:
            self.stdout.write(self.style.SUCCESS(
                f'✓ Created Free Trial plan (ID: {plan.id})'
            ))
        else:
            self.stdout.write(self.style.SUCCESS(
                f'✓ Updated Free Trial plan (ID: {plan.id})'
            ))
        
        self.stdout.write(self.style.SUCCESS(
            f'  - Credits: {plan.included_credits}'
        ))
        self.stdout.write(self.style.SUCCESS(
            f'  - Max Sites: {plan.max_sites}'
        ))
        self.stdout.write(self.style.SUCCESS(
            f'  - Max Sectors: {plan.max_industries}'
        ))
        self.stdout.write(self.style.SUCCESS(
            f'  - Status: {"Active" if plan.is_active else "Inactive"}'
        ))
        
        self.stdout.write(self.style.SUCCESS(
            '\nFree Trial plan is ready for signup!'
        ))