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


class Command(BaseCommand):
    help = 'Populate expertise items for existing services'

    def handle(self, *args, **options):
        with transaction.atomic():
            # Expertise data for each service
            expertise_data = {
                'enterprise-web-application': [
                    {
                        'title': 'Expert Development Team',
                        'description': 'Our experienced team specializes in enterprise web applications with years of industry expertise. We bring deep knowledge and proven methodologies to every project.',
                        'icon': 'users',
                        'display_order': 1
                    },
                    {
                        'title': 'Modern Technology Stack',
                        'description': 'We use cutting-edge technologies and frameworks to deliver scalable, secure, and future-proof web applications.',
                        'icon': 'code',
                        'display_order': 2
                    },
                    {
                        'title': 'Proven Track Record',
                        'description': 'We have successfully delivered enterprise web applications to numerous clients, helping them achieve their business goals and drive growth.',
                        'icon': 'chart-line',
                        'display_order': 3
                    }
                ],
                'cross-platform-mobile-app': [
                    {
                        'title': 'Mobile Development Experts',
                        'description': 'Our specialized mobile development team has extensive experience in both native and cross-platform app development.',
                        'icon': 'mobile',
                        'display_order': 1
                    },
                    {
                        'title': 'Cross-Platform Mastery',
                        'description': 'We excel in React Native and Flutter development, delivering high-performance apps for both iOS and Android platforms.',
                        'icon': 'layer-group',
                        'display_order': 2
                    },
                    {
                        'title': 'App Store Success',
                        'description': 'We have successfully launched numerous apps in both Apple App Store and Google Play Store with excellent ratings.',
                        'icon': 'store',
                        'display_order': 3
                    }
                ],
                'restful-api-development': [
                    {
                        'title': 'API Architecture Experts',
                        'description': 'Our team specializes in designing and building robust, scalable APIs that power modern applications.',
                        'icon': 'network-wired',
                        'display_order': 1
                    },
                    {
                        'title': 'Performance Optimization',
                        'description': 'We create high-performance APIs with caching, rate limiting, and optimization techniques for maximum efficiency.',
                        'icon': 'gauge',
                        'display_order': 2
                    },
                    {
                        'title': 'Comprehensive Documentation',
                        'description': 'We provide detailed API documentation with interactive examples and SDKs for easy integration.',
                        'icon': 'book',
                        'display_order': 3
                    }
                ],
                'cloud-migration-devops': [
                    {
                        'title': 'Cloud Migration Specialists',
                        'description': 'Our certified cloud engineers have extensive experience in migrating complex infrastructures with minimal downtime.',
                        'icon': 'cloud',
                        'display_order': 1
                    },
                    {
                        'title': 'DevOps Automation',
                        'description': 'We implement complete CI/CD pipelines and automation workflows to streamline your development process.',
                        'icon': 'cogs',
                        'display_order': 2
                    },
                    {
                        'title': 'Cost Optimization',
                        'description': 'We help optimize your cloud costs while maintaining performance and reliability standards.',
                        'icon': 'dollar-sign',
                        'display_order': 3
                    }
                ],
                'ai-powered-business-intelligence': [
                    {
                        'title': 'AI & ML Specialists',
                        'description': 'Our data scientists and AI engineers have deep expertise in machine learning and business intelligence solutions.',
                        'icon': 'brain',
                        'display_order': 1
                    },
                    {
                        'title': 'Advanced Analytics',
                        'description': 'We create sophisticated analytics platforms that transform raw data into actionable business insights.',
                        'icon': 'chart-bar',
                        'display_order': 2
                    },
                    {
                        'title': 'Predictive Modeling',
                        'description': 'Our team builds advanced predictive models that help businesses make data-driven decisions.',
                        'icon': 'crystal-ball',
                        'display_order': 3
                    }
                ],
                'ecommerce-platform': [
                    {
                        'title': 'E-commerce Specialists',
                        'description': 'Our team has extensive experience in building high-converting e-commerce platforms for various industries.',
                        'icon': 'shopping-cart',
                        'display_order': 1
                    },
                    {
                        'title': 'Payment Integration',
                        'description': 'We integrate secure payment gateways and ensure PCI compliance for safe transactions.',
                        'icon': 'credit-card',
                        'display_order': 2
                    },
                    {
                        'title': 'SEO & Performance',
                        'description': 'We optimize e-commerce sites for search engines and performance to maximize conversions.',
                        'icon': 'search',
                        'display_order': 3
                    }
                ]
            }

            for service_slug, expertise_items in expertise_data.items():
                try:
                    service = Service.objects.get(slug=service_slug)
                    
                    # Clear existing expertise items
                    ServiceExpertise.objects.filter(service=service).delete()
                    
                    # Create new expertise items
                    for expertise_data in expertise_items:
                        ServiceExpertise.objects.create(
                            service=service,
                            **expertise_data
                        )
                    
                    self.stdout.write(f'Added expertise items 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 expertise items!')
        )
