from django.core.management.base import BaseCommand
from django.db import transaction
from services.models import Service


class Command(BaseCommand):
    help = 'Populate section descriptions for existing services'

    def handle(self, *args, **options):
        with transaction.atomic():
            # Section descriptions for each service
            descriptions_data = {
                'enterprise-web-application': {
                    'features_description': 'Our enterprise web applications are built with cutting-edge technologies and industry best practices to deliver exceptional performance and user experience.',
                    'deliverables_description': 'Get a complete enterprise-grade web application with advanced features, comprehensive documentation, and ongoing support.',
                    'process_description': 'We follow a structured 8-step development process that ensures quality, efficiency, and timely delivery of your enterprise web application.',
                    'why_choose_description': 'Why choose our Enterprise Web Application service?',
                    'expertise_description': 'Our team brings years of experience in enterprise web development, combining technical expertise with business understanding.'
                },
                'cross-platform-mobile-app': {
                    'features_description': 'Our cross-platform mobile apps deliver native-like performance while reducing development time and costs significantly.',
                    'deliverables_description': 'Receive a fully functional mobile app for both iOS and Android platforms, complete with app store deployment support.',
                    'process_description': 'Our proven mobile development methodology ensures your app meets all platform requirements and user expectations.',
                    'why_choose_description': 'Why choose our Cross-Platform Mobile App service?',
                    'expertise_description': 'We specialize in React Native and Flutter development, delivering high-performance apps that work seamlessly across platforms.'
                },
                'restful-api-development': {
                    'features_description': 'Our RESTful APIs are designed for scalability, security, and ease of integration with comprehensive documentation.',
                    'deliverables_description': 'Get a robust, well-documented API with SDKs, testing tools, and comprehensive integration support.',
                    'process_description': 'We follow API-first development principles to ensure your API is reliable, scalable, and developer-friendly.',
                    'why_choose_description': 'Why choose our RESTful API Development service?',
                    'expertise_description': 'Our API specialists have extensive experience in designing and building enterprise-grade APIs for various industries.'
                },
                'cloud-migration-devops': {
                    'features_description': 'Our cloud migration and DevOps services ensure seamless transition to the cloud with zero downtime and improved performance.',
                    'deliverables_description': 'Complete cloud migration with automated CI/CD pipelines, monitoring, and cost optimization strategies.',
                    'process_description': 'Our systematic approach to cloud migration minimizes risks while maximizing the benefits of cloud infrastructure.',
                    'why_choose_description': 'Why choose our Cloud Migration & DevOps service?',
                    'expertise_description': 'We are certified cloud architects with proven experience in migrating complex infrastructures and implementing DevOps practices.'
                },
                'ai-powered-business-intelligence': {
                    'features_description': 'Transform your data into actionable insights with our AI-powered business intelligence solutions.',
                    'deliverables_description': 'Get a complete BI platform with AI-powered analytics, predictive models, and interactive dashboards.',
                    'process_description': 'Our data science methodology ensures your BI solution provides accurate insights and drives informed decision-making.',
                    'why_choose_description': 'Why choose our AI-Powered Business Intelligence service?',
                    'expertise_description': 'Our data scientists and AI engineers specialize in creating intelligent solutions that turn data into competitive advantage.'
                },
                'ecommerce-platform': {
                    'features_description': 'Build a high-converting e-commerce platform with advanced features, secure payments, and mobile optimization.',
                    'deliverables_description': 'Get a complete e-commerce solution with payment integration, inventory management, and marketing tools.',
                    'process_description': 'We follow e-commerce best practices to ensure your platform drives sales and provides excellent customer experience.',
                    'why_choose_description': 'Why choose our E-commerce Platform service?',
                    'expertise_description': 'Our e-commerce specialists have built successful online stores for businesses across various industries and sizes.'
                }
            }

            for service_slug, descriptions in descriptions_data.items():
                try:
                    service = Service.objects.get(slug=service_slug)
                    
                    # Update service with new descriptions
                    for field, value in descriptions.items():
                        setattr(service, field, value)
                    
                    service.save()
                    self.stdout.write(f'Updated section descriptions for: {service.title}')
                    
                except Service.DoesNotExist:
                    self.stdout.write(
                        self.style.WARNING(f'Service with slug "{service_slug}" not found')
                    )

        self.stdout.write(
            self.style.SUCCESS('Successfully populated section descriptions!')
        )
