from django.core.management.base import BaseCommand
from case_studies.models import CaseStudyCategory, Client, CaseStudy, CaseStudyImage, CaseStudyProcess
from django.utils import timezone
from datetime import timedelta


class Command(BaseCommand):
    help = 'Populate database with sample case study data'

    def handle(self, *args, **options):
        self.stdout.write(self.style.SUCCESS('Starting to populate case study data...'))

        # Clear existing data
        CaseStudyProcess.objects.all().delete()
        CaseStudyImage.objects.all().delete()
        CaseStudy.objects.all().delete()
        Client.objects.all().delete()
        CaseStudyCategory.objects.all().delete()

        # Create Categories
        categories_data = [
            {
                'name': '3D Render',
                'slug': '3d-render',
                'description': '3D rendering and visualization projects',
                'display_order': 1
            },
            {
                'name': 'UI / UX',
                'slug': 'ui-ux',
                'description': 'User interface and user experience design projects',
                'display_order': 2
            },
            {
                'name': 'Photography',
                'slug': 'photography',
                'description': 'Professional photography projects',
                'display_order': 3
            },
            {
                'name': 'AI',
                'slug': 'ai',
                'description': 'Artificial intelligence and machine learning projects',
                'display_order': 4
            },
            {
                'name': 'Icon Set',
                'slug': 'icon-set',
                'description': 'Custom icon set design projects',
                'display_order': 5
            },
            {
                'name': 'Road Map',
                'slug': 'road-map',
                'description': 'Product roadmap and planning projects',
                'display_order': 6
            }
        ]

        categories = {}
        for cat_data in categories_data:
            category = CaseStudyCategory.objects.create(**cat_data)
            categories[category.slug] = category
            self.stdout.write(f'Created category: {category.name}')

        # Create Clients
        clients_data = [
            {
                'name': 'Tarapio',
                'slug': 'tarapio',
                'description': 'Leading technology solutions provider',
                'website': 'https://tarapio.com'
            },
            {
                'name': 'Melenpo',
                'slug': 'melenpo',
                'description': 'Digital innovation company',
                'website': 'https://melenpo.com'
            },
            {
                'name': 'Polax',
                'slug': 'polax',
                'description': 'Enterprise software solutions',
                'website': 'https://polax.com'
            },
            {
                'name': 'AINA',
                'slug': 'aina',
                'description': 'AI and automation solutions',
                'website': 'https://aina.com'
            }
        ]

        clients = {}
        for client_data in clients_data:
            client = Client.objects.create(**client_data)
            clients[client.slug] = client
            self.stdout.write(f'Created client: {client.name}')

        # Create Case Studies
        case_studies_data = [
            {
                'title': '3D computer graphics, or "3D graphics',
                'subtitle': 'Immersive 3D Visualization Experience',
                'description': '''
<h2>Project Overview</h2>
<p>A comprehensive 3D rendering project that showcases cutting-edge visualization techniques and photorealistic rendering capabilities. This project demonstrates our expertise in creating stunning visual content for modern digital platforms.</p>

<h3>The Challenge</h3>
<p>Our client needed high-quality 3D visualizations that could accurately represent their products in a digital environment. The challenge was to create renders that were not only photorealistic but also optimized for various platforms and use cases.</p>

<h3>Our Approach</h3>
<p>We employed advanced 3D modeling techniques combined with physically-based rendering (PBR) to achieve exceptional results. Our team utilized industry-standard tools and custom workflows to deliver renders that exceeded client expectations.</p>

<h3>Key Features</h3>
<ul>
<li>Photorealistic lighting and materials</li>
<li>High-resolution textures and details</li>
<li>Multiple viewing angles and perspectives</li>
<li>Optimized assets for web and print</li>
<li>Interactive 3D viewer integration</li>
</ul>

<h2>Results</h2>
<p>The project resulted in a collection of stunning 3D renders that significantly enhanced the client's digital presence. The visualizations led to increased customer engagement and improved conversion rates across their digital channels.</p>
                ''',
                'category': categories['3d-render'],
                'client': None,
                'thumbnail_url': '/images/case/two.png',
                'poster_image_url': '/images/case/poster.png',
                'project_image_url': '/images/case/project.png',
                'project_overview': 'Lorem ipsum dolor sit amet consectetur. Vestibulum malesuada amet sagittis urna. Mattis eget ultricies est morbi velit ultrices viverra elit facilisi.',
                'site_map_content': 'Lorem ipsum dolor sit amet consectetur. Vestibulum malesuada amet sagittis urna. Mattis eget ultricies est morbi velit ultrices viverra elit facilisi.',
                'featured': True,
                'display_order': 1,
                'days_ago': 10
            },
            {
                'title': 'Artificial intelligence is the simulation of human processes',
                'subtitle': 'AI-Powered Business Solutions',
                'description': '''
<h2>About the Project</h2>
<p>This artificial intelligence project demonstrates the power of machine learning and AI in solving complex business problems. We developed custom AI models that automate decision-making processes and provide predictive insights.</p>

<h3>Technology Stack</h3>
<p>The project utilizes state-of-the-art AI technologies including neural networks, natural language processing, and computer vision. Our solution is built on a scalable cloud infrastructure that can handle large volumes of data processing.</p>

<h3>Implementation</h3>
<p>We worked closely with the client to understand their specific needs and challenges. The implementation phase involved data collection, model training, validation, and deployment to production environments.</p>

<h2>Impact</h2>
<p>The AI solution has transformed the client's operations, reducing manual work by 60% and improving accuracy in decision-making processes. The system continues to learn and improve over time, providing increasing value to the organization.</p>
                ''',
                'category': categories['ai'],
                'client': clients['tarapio'],
                'thumbnail_url': '/images/case/one.png',
                'poster_image_url': '/images/case/poster.png',
                'featured': True,
                'display_order': 2,
                'days_ago': 15
            },
            {
                'title': 'User experience (UX) design is the process design teams',
                'subtitle': 'Modern UX Design System',
                'description': '''
<h2>Project Summary</h2>
<p>A comprehensive UX design project focused on creating intuitive and engaging user experiences. This case study showcases our approach to user-centered design and our ability to create interfaces that delight users.</p>

<h3>Research and Discovery</h3>
<p>We conducted extensive user research including interviews, surveys, and usability testing to understand user needs and pain points. This research formed the foundation of our design decisions.</p>

<h3>Design Process</h3>
<p>Our design process involved creating user personas, journey maps, wireframes, and high-fidelity prototypes. Each step was validated with real users to ensure we were on the right track.</p>

<h2>Deliverables</h2>
<ul>
<li>Comprehensive design system</li>
<li>Interactive prototypes</li>
<li>User flow diagrams</li>
<li>Accessibility guidelines</li>
<li>Component library</li>
</ul>
                ''',
                'category': categories['ui-ux'],
                'client': clients['melenpo'],
                'thumbnail_url': '/images/case/three.png',
                'poster_image_url': '/images/case/poster.png',
                'featured': False,
                'display_order': 3,
                'days_ago': 20
            },
            {
                'title': 'Photography is the art, application, and practice',
                'subtitle': 'Professional Photography Portfolio',
                'description': '''
<h2>About This Project</h2>
<p>A stunning photography project that captures the essence of modern visual storytelling. This portfolio demonstrates our expertise in various photography styles and techniques.</p>

<h3>Photography Style</h3>
<p>The project incorporates multiple photography styles including product photography, portrait photography, and architectural photography. Each image is carefully composed and post-processed to achieve the desired aesthetic.</p>

<h2>Technical Excellence</h2>
<p>Using professional-grade equipment and advanced lighting techniques, we created images that stand out in quality and artistic vision.</p>
                ''',
                'category': categories['photography'],
                'client': None,
                'thumbnail_url': '/images/case/four.png',
                'poster_image_url': '/images/case/poster.png',
                'featured': False,
                'display_order': 4,
                'days_ago': 25
            },
            {
                'title': 'UX case study for a medical app- medical product design',
                'subtitle': 'Healthcare UX Innovation',
                'description': '''
<h2>Healthcare Design Challenge</h2>
<p>Designing for healthcare requires special attention to accessibility, security, and user trust. This medical app design project showcases our expertise in creating intuitive interfaces for complex healthcare workflows.</p>

<h3>Compliance and Security</h3>
<p>The design adheres to HIPAA regulations and industry best practices for healthcare data security while maintaining an intuitive user experience.</p>

<h2>User Research</h2>
<p>We conducted extensive research with healthcare professionals and patients to ensure the design meets the needs of all stakeholders.</p>
                ''',
                'category': categories['ui-ux'],
                'client': clients['polax'],
                'thumbnail_url': '/images/case/five.png',
                'poster_image_url': '/images/case/poster.png',
                'featured': False,
                'display_order': 5,
                'days_ago': 30
            },
            {
                'title': 'Make icon set for the educational project',
                'subtitle': 'Custom Educational Icon Set',
                'description': '''
<h2>Icon Design Project</h2>
<p>A comprehensive icon set designed specifically for educational platforms. This project demonstrates our ability to create cohesive, scalable, and meaningful iconography.</p>

<h3>Design Principles</h3>
<p>The icons follow consistent design principles including size, style, and metaphor. Each icon is designed to be instantly recognizable and appropriate for educational contexts.</p>

<h2>Deliverables</h2>
<p>The final deliverable includes icons in multiple formats (SVG, PNG) and sizes, along with comprehensive usage guidelines.</p>
                ''',
                'category': categories['icon-set'],
                'client': None,
                'thumbnail_url': '/images/case/six.png',
                'poster_image_url': '/images/case/poster.png',
                'featured': False,
                'display_order': 6,
                'days_ago': 35
            },
            {
                'title': 'AI-driven user experience design process',
                'subtitle': 'AI-Driven User Experience',
                'description': '''
<h2>AI-Enhanced UX Design</h2>
<p>This project combines artificial intelligence with user experience design to create adaptive interfaces that learn from user behavior and preferences.</p>

<h3>Innovation</h3>
<p>The design incorporates machine learning algorithms that personalize the user experience based on individual usage patterns and preferences.</p>
                ''',
                'category': categories['ai'],
                'client': clients['aina'],
                'thumbnail_url': '/images/case/seven.png',
                'poster_image_url': '/images/case/poster.png',
                'featured': False,
                'display_order': 7,
                'days_ago': 40
            },
            {
                'title': 'UX site rode map app product design system',
                'subtitle': 'Product Roadmap Visualization',
                'description': '''
<h2>Product Roadmap Design</h2>
<p>A comprehensive product roadmap visualization system that helps teams plan, communicate, and execute their product strategy effectively.</p>

<h3>Features</h3>
<p>The roadmap system includes timeline views, milestone tracking, dependency mapping, and collaboration tools for distributed teams.</p>

<h2>Implementation</h2>
<p>Built with modern web technologies and optimized for performance and usability across all devices and platforms.</p>
                ''',
                'category': categories['road-map'],
                'client': None,
                'thumbnail_url': '/images/case/eight.png',
                'poster_image_url': '/images/case/poster.png',
                'featured': False,
                'display_order': 8,
                'days_ago': 45
            }
        ]

        # Create case studies
        created_case_studies = []
        for cs_data in case_studies_data:
            days_ago = cs_data.pop('days_ago')
            
            case_study = CaseStudy.objects.create(
                **cs_data,
                published_at=timezone.now() - timedelta(days=days_ago)
            )
            created_case_studies.append(case_study)
            
            # Add gallery images
            gallery_images = [
                '/images/case/nine.png',
                '/images/case/ten.png',
                '/images/case/eleven.png',
                '/images/case/twelve.png'
            ]
            
            for idx, img_url in enumerate(gallery_images, 1):
                CaseStudyImage.objects.create(
                    case_study=case_study,
                    image_url=img_url,
                    caption=f'Gallery Image {idx}',
                    display_order=idx
                )
            
            # Add process steps
            processes = [
                {'step_number': 1, 'title': 'Computer Vision', 'description': 'Quisque varius malesuada dui, ut posuere purus gravida in. Phasellus ultricies ullamcorper mollis.'},
                {'step_number': 2, 'title': 'Computer Vision', 'description': 'Quisque varius malesuada dui, ut posuere purus gravida in. Phasellus ultricies ullamcorper mollis.'},
                {'step_number': 3, 'title': '3D Vision', 'description': 'Quisque varius malesuada dui, ut posuere purus gravida in. Phasellus ultricies ullamcorper mollis.'},
                {'step_number': 4, 'title': 'Computer Vision', 'description': 'Quisque varius malesuada dui, ut posuere purus gravida in. Phasellus ultricies ullamcorper mollis.'},
                {'step_number': 5, 'title': '3D Vision', 'description': 'Quisque varius malesuada dui, ut posuere purus gravida in. Phasellus ultricies ullamcorper mollis.'},
            ]
            
            for process_data in processes:
                CaseStudyProcess.objects.create(
                    case_study=case_study,
                    **process_data
                )
            
            self.stdout.write(f'Created case study: {case_study.title}')

        self.stdout.write(self.style.SUCCESS('\nSuccessfully populated case study data!'))
        self.stdout.write(f'Created {CaseStudyCategory.objects.count()} categories')
        self.stdout.write(f'Created {Client.objects.count()} clients')
        self.stdout.write(f'Created {CaseStudy.objects.count()} case studies')
        self.stdout.write(f'Created {CaseStudyImage.objects.count()} gallery images')
        self.stdout.write(f'Created {CaseStudyProcess.objects.count()} process steps')

