"""Seed Peza Job Zambia podcast episodes for UI / sitemap testing (temporary)."""

from django.core.management.base import BaseCommand

from podcast.models import PodcastEpisode


EPISODES = [
    {
        'slug': 'academic-qualifications-explained',
        'title': 'Academic Qualifications Explained — From Certificate to PhD',
        'episode_number': 1,
        'guest_name': 'Griffins Mandanda',
        'description': (
            'Peza Job Zambia founder Griffins Mandanda breaks down common academic '
            'qualifications in Zambia and beyond — certificates, diplomas, degrees, '
            'and professional credentials — and how to choose the right path for your career.'
        ),
        'duration_display': '38 min',
        'cover_image_url': 'https://images.unsplash.com/photo-1478737270239-2f02b77fc618?w=1200&q=80',
        'audio_url': 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3',
        'is_featured': True,
    },
    {
        'slug': 'write-a-cv-that-gets-interviews',
        'title': 'Write a CV That Gets You Interviews in Zambia',
        'episode_number': 2,
        'guest_name': 'Griffins Mandanda',
        'description': (
            'Practical CV advice for Zambian job seekers: formatting, achievements, '
            'keywords recruiters look for, and the mistakes that get applications ignored.'
        ),
        'duration_display': '32 min',
        'cover_image_url': 'https://images.unsplash.com/photo-1590602847861-f357a9332bbc?w=1200&q=80',
        'audio_url': 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-2.mp3',
    },
    {
        'slug': 'ace-your-job-interview',
        'title': 'Ace Your Job Interview — Preparation That Works',
        'episode_number': 3,
        'guest_name': 'Griffins Mandanda',
        'description': (
            'How to prepare for common interview questions, communicate your value, '
            'use the STAR method, and follow up after interviews in the Zambian job market.'
        ),
        'duration_display': '41 min',
        'cover_image_url': 'https://images.unsplash.com/photo-1573497019940-1c28c88b4f3e?w=1200&q=80',
        'audio_url': 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3',
    },
    {
        'slug': 'choosing-the-right-course-for-your-career',
        'title': 'Choosing the Right Course for Your Career',
        'episode_number': 4,
        'guest_name': 'Griffins Mandanda',
        'description': (
            'Align your education with market demand. We discuss course selection, '
            'institution quality, and how to avoid costly qualification mistakes.'
        ),
        'duration_display': '29 min',
        'cover_image_url': 'https://images.unsplash.com/photo-1511671782779-c97d3d27a1d4?w=1200&q=80',
        'audio_url': 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-4.mp3',
    },
    {
        'slug': 'smart-job-search-strategies-zambia',
        'title': 'Smart Job Search Strategies for Zambian Professionals',
        'episode_number': 5,
        'guest_name': 'Griffins Mandanda',
        'description': (
            'Where to look for jobs, how to network, tailor applications, and stay '
            'resilient during your search — a playbook for today\'s Zambian workforce.'
        ),
        'duration_display': '35 min',
        'cover_image_url': 'https://images.unsplash.com/photo-1454165804603-c3d57bc86b40?w=1200&q=80',
        'audio_url': 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-5.mp3',
    },
]


class Command(BaseCommand):
    help = 'Seed test podcast episodes by Peza Job Zambia (temporary — for homepage testing)'

    def add_arguments(self, parser):
        parser.add_argument(
            '--only',
            action='store_true',
            help='Delete all other podcast episodes and keep only these test episodes',
        )

    def handle(self, *args, **options):
        slugs = [e['slug'] for e in EPISODES]
        if options['only']:
            removed, _ = PodcastEpisode.objects.exclude(slug__in=slugs).delete()
            if removed:
                self.stdout.write(f'Removed {removed} other podcast episode(s).')

        for data in EPISODES:
            PodcastEpisode.objects.update_or_create(
                slug=data['slug'],
                defaults={**data, 'is_published': True},
            )

        self.stdout.write(
            self.style.SUCCESS(f'Seeded {len(EPISODES)} test podcast episodes: {", ".join(slugs)}')
        )
