from django.core.management.base import BaseCommand
from deals.models import Category, Deal, NavigationItem, Page, PageSection, SiteSettings, TrustBenefit


CATEGORIES = [
    ('Dental', 'dental', '🦷', 'Advanced care for a healthier smile', '/dental-treatment.png'),
    ('Beauty', 'beauty', '🌸', 'Look good and feel amazing', '/beauty-treatment.png'),
    ('Ayurveda', 'ayurveda', '🌿', 'Natural healing and holistic wellness', '/ayurvedic-treatment.png'),
    ('Skin Care', 'skincare', '🍃', 'Healthy skin, confident you', '/skin-treatment.png'),
]

DEALS = [
    ('dental', 'Teeth Whitening', 'teeth-whitening', 'Smile Care Dental Clinic', 'Kochi', 1999, 4999, 4.8, 1200, 'https://images.unsplash.com/photo-1609840114035-3c981b782dfe?auto=format&fit=crop&w=900&q=80'),
    ('dental', 'Scaling + Polishing', 'scaling-polishing', 'DentaCare', 'Kottayam', 1199, 2200, 4.7, 980, 'https://images.unsplash.com/photo-1588776814546-1ffcf47267a5?auto=format&fit=crop&w=900&q=80'),
    ('beauty', 'Hydra Facial', 'hydra-facial', 'Glow Skin Clinic', 'Calicut', 2499, 4999, 4.8, 760, 'https://images.unsplash.com/photo-1487412720507-e7ab37603c6f?auto=format&fit=crop&w=900&q=80'),
    ('ayurveda', 'Aroma Oil Massage', 'aroma-oil-massage', 'Bliss Spa', 'Thrissur', 1499, 2499, 4.7, 640, 'https://images.unsplash.com/photo-1600334129128-685c5582fd35?auto=format&fit=crop&w=900&q=80'),
    ('ayurveda', 'Ayurvedic Therapy', 'ayurvedic-therapy', 'Ayurveda Healing Center', 'Alappuzha', 1299, 2599, 4.6, 520, 'https://images.unsplash.com/photo-1544161515-4ab6ce6db874?auto=format&fit=crop&w=900&q=80'),
]


class Command(BaseCommand):
    help = 'Create starter ASNDeals categories and featured deals'

    def handle(self, *args, **options):
        categories = {}
        for name, slug, icon, description, image_url in CATEGORIES:
            category, _ = Category.objects.update_or_create(slug=slug, defaults={'name': name, 'icon': icon, 'description': description, 'image_url': image_url})
            categories[slug] = category
        for category_slug, title, slug, clinic, city, price, original_price, rating, reviews, image_url in DEALS:
            Deal.objects.update_or_create(slug=slug, defaults={'category': categories[category_slug], 'title': title, 'clinic': clinic, 'city': city, 'price': price, 'original_price': original_price, 'rating': rating, 'review_count': reviews, 'image_url': image_url, 'featured': True, 'active': True, 'description': f'Book {title.lower()} with a verified ASNDeals provider.'})
        SiteSettings.objects.update_or_create(pk=1, defaults={
            'site_name': 'ASNDeals', 'tagline': 'Better care, fairer prices',
            'hero_badge': "India's trusted wellness marketplace",
            'hero_title': 'Feel better. Look brighter. Pay less.',
            'hero_description': 'Verified dental, beauty, skin care and Ayurveda offers from trusted clinics across Kerala.',
            'support_email': 'support@asndeals.com', 'footer_text': 'Better care, fairer prices.'
        })
        page_specs = [
            ('About ASNDeals', 'about', 'A trusted marketplace for health and wellness offers.', 'ASNDeals connects customers with verified clinics and wellness providers across Kerala.'),
            ('Dental Treatments', 'dental', 'Advanced care for a healthier smile.', 'Compare verified dental providers, prices and treatment packages.'),
            ('Beauty Treatments', 'beauty', 'Look good and feel amazing.', 'Discover beauty services and offers from trusted professionals.'),
            ('Skin Care', 'skincare', 'Healthy skin, confident you.', 'Explore skin care consultations and treatment packages.'),
            ('Ayurveda', 'ayurveda', 'Natural healing and holistic wellness.', 'Find authentic Ayurveda therapies and wellness providers.'),
            ('How It Works', 'how-it-works', 'Find, compare and book in a few simple steps.', 'Browse offers, choose a provider and send your booking request securely.'),
            ('Contact & Support', 'support', 'We are here to help.', 'Contact the ASNDeals support team for booking or account assistance.'),
        ]
        for order, (title, slug, summary, body) in enumerate(page_specs):
            page, _ = Page.objects.update_or_create(slug=slug, defaults={'title': title, 'summary': summary, 'body': body, 'published': True, 'sort_order': order, 'meta_title': f'{title} | ASNDeals', 'meta_description': summary})
            PageSection.objects.update_or_create(page=page, sort_order=0, defaults={'heading': title, 'subheading': summary, 'body': body, 'active': True})
        nav_specs = [('Home', '/'), ('Dental', '/pages/dental'), ('Beauty', '/pages/beauty'), ('Skin Care', '/pages/skincare'), ('Ayurveda', '/pages/ayurveda'), ('How It Works', '/pages/how-it-works'), ('Support', '/pages/support')]
        for order, (label, url) in enumerate(nav_specs):
            NavigationItem.objects.update_or_create(label=label, defaults={'url': url, 'sort_order': order, 'active': True})
        benefit_specs = [
            ('🛡', 'Trusted & Verified', 'All clinics and professionals are verified'),
            ('🏅', 'Best Price Guarantee', 'Get the best deals with no hidden charges'),
            ('📅', 'Easy Booking', 'Book appointments in just a few clicks'),
            ('🔒', 'Secure Payments', '100% secure payments and data protection'),
            ('🎧', '24/7 Customer Support', 'We are here to help you anytime'),
        ]
        for order, (icon, title, description) in enumerate(benefit_specs):
            TrustBenefit.objects.update_or_create(title=title, defaults={'icon': icon, 'description': description, 'sort_order': order, 'active': True})
        self.stdout.write(self.style.SUCCESS('ASNDeals starter data is ready.'))
