"""
About Page Seeder
Seeds the database with comprehensive about page content
All images are from Unsplash (free stock photos)
"""
import json
import sys
from pathlib import Path
from datetime import datetime, timezone

# Add parent directory to path to allow importing from src
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))

from sqlalchemy.orm import Session
from src.shared.config.database import SessionLocal
from src.shared.config.logging_config import get_logger
from src.content.models.page_content import PageContent, PageType

# Import all models to ensure relationships are loaded
from src.models import *

logger = get_logger(__name__)


def get_about_page_data():
    """Generate comprehensive about page data with Unsplash images"""
    
    now = datetime.now(timezone.utc)
    
    return {
        'page_type': PageType.ABOUT,
        'title': 'About Our Hotel',
        'subtitle': 'A Legacy of Luxury and Exceptional Service',
        'description': 'Discover our rich heritage spanning three decades. We have been crafting exceptional experiences for discerning travelers worldwide, blending timeless elegance with modern amenities.',
        'content': '<p>For over three decades, we have been at the forefront of luxury hospitality, creating unforgettable experiences for our guests. Our commitment to excellence, attention to detail, and passion for service has made us a destination of choice for travelers seeking the finest in accommodation, dining, and personalized service.</p>',
        'meta_title': 'About Us | Luxury Hotel & Resort - Our Story, Mission & Vision',
        'meta_description': 'Learn about our luxury hotel\'s rich heritage, mission, vision, and commitment to exceptional hospitality. Discover our story spanning three decades of excellence.',
        'meta_keywords': 'about us, hotel history, luxury hospitality, hotel mission, hotel vision, hotel story, luxury hotel',
        'og_title': 'About Our Luxury Hotel - A Legacy of Excellence',
        'og_description': 'Discover our rich heritage spanning three decades. We have been crafting exceptional experiences for discerning travelers worldwide.',
        'og_image': 'https://images.unsplash.com/photo-1520250497591-112f2f40a3f4?w=1200&h=630&fit=crop',
        'canonical_url': 'https://luxuryhotel.com/about',
        'hero_title': 'Our Story',
        'hero_subtitle': 'Three Decades of Excellence in Luxury Hospitality',
        'hero_image': 'https://images.unsplash.com/photo-1520250497591-112f2f40a3f4?w=1920&h=1080&fit=crop',
        'hero_video_url': None,
        'hero_video_poster': None,
        'about_hero_image': 'https://images.unsplash.com/photo-1566073771259-6a8506099945?w=1400&h=900&fit=crop',
        'story_content': '<p>Founded in 1993, our hotel began as a vision to create a sanctuary of luxury and sophistication in the heart of the city. What started as a small boutique property has grown into an internationally recognized destination, consistently ranked among the world\'s finest hotels.</p><p>Over the years, we have welcomed countless guests, from world leaders and celebrities to families celebrating special moments. Each guest has contributed to our story, and we are honored to have been part of their journeys.</p><p>Our commitment to excellence has never wavered. We continuously invest in our facilities, train our staff to the highest standards, and innovate to exceed expectations. Today, we stand as a testament to what is possible when passion meets dedication.</p>',
        'mission': '<p>Our mission is to provide unparalleled luxury experiences that exceed expectations. We are committed to creating memorable moments for every guest through exceptional service, world-class amenities, and attention to every detail. We strive to be the benchmark of excellence in hospitality, where every interaction reflects our dedication to perfection.</p>',
        'vision': '<p>Our vision is to be the world\'s most respected luxury hotel brand, recognized for our unwavering commitment to excellence, innovation, and sustainable luxury. We envision a future where our guests feel truly at home, where our team members are proud ambassadors of our values, and where our community benefits from our presence and commitment to responsible hospitality.</p>',
        'values': json.dumps([
            {
                'icon': 'heart',
                'title': 'Excellence',
                'description': 'We strive for perfection in every detail, ensuring your experience exceeds expectations. Excellence is not a goal but a standard we maintain in everything we do.'
            },
            {
                'icon': 'users',
                'title': 'Hospitality',
                'description': 'Our dedicated team provides warm, personalized service to make you feel at home. We believe true hospitality comes from the heart and is reflected in every interaction.'
            },
            {
                'icon': 'leaf',
                'title': 'Sustainability',
                'description': 'Committed to eco-friendly practices for a better future and a delightful stay. We balance luxury with responsibility, ensuring our operations protect the environment for future generations.'
            },
            {
                'icon': 'award',
                'title': 'Quality',
                'description': 'We maintain the highest standards in service, amenities, and guest satisfaction. Quality is embedded in our culture and evident in every aspect of your stay.'
            },
            {
                'icon': 'handshake',
                'title': 'Integrity',
                'description': 'We conduct our business with honesty, transparency, and ethical practices. Trust is the foundation of our relationships with guests, partners, and our community.'
            },
            {
                'icon': 'lightbulb',
                'title': 'Innovation',
                'description': 'We embrace new technologies and creative solutions to enhance your experience. Innovation drives us to continuously improve and stay ahead of industry trends.'
            }
        ]),
        'team': json.dumps([
            {
                'name': 'Sarah Johnson',
                'position': 'General Manager',
                'bio': 'With over 20 years of experience in luxury hospitality, Sarah leads our team with passion and dedication. Her commitment to excellence has been instrumental in our success.',
                'image': 'https://images.unsplash.com/photo-1494790108377-be9c29b29330?w=400&h=400&fit=crop&crop=face',
                'social': {
                    'linkedin': 'https://linkedin.com/in/sarahjohnson',
                    'twitter': 'https://twitter.com/sarahjohnson'
                }
            },
            {
                'name': 'Michael Chen',
                'position': 'Executive Chef',
                'bio': 'Award-winning chef with a passion for creating culinary masterpieces. Michael brings innovative flavors and techniques to our restaurants, delighting guests with every dish.',
                'image': 'https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=400&h=400&fit=crop&crop=face',
                'social': {
                    'linkedin': 'https://linkedin.com/in/michaelchen',
                    'instagram': 'https://instagram.com/chefmichael'
                }
            },
            {
                'name': 'Emily Rodriguez',
                'position': 'Director of Guest Services',
                'bio': 'Emily ensures every guest receives personalized attention and exceptional service. Her warm personality and attention to detail make her a favorite among our guests.',
                'image': 'https://images.unsplash.com/photo-1438761681033-6461ffad8d80?w=400&h=400&fit=crop&crop=face',
                'social': {
                    'linkedin': 'https://linkedin.com/in/emilyrodriguez'
                }
            },
            {
                'name': 'David Thompson',
                'position': 'Spa Director',
                'bio': 'With expertise in wellness and holistic healing, David has created a world-class spa experience. His innovative treatments and serene environment provide guests with ultimate relaxation.',
                'image': 'https://images.unsplash.com/photo-1500648767791-00dcc994a43e?w=400&h=400&fit=crop&crop=face',
                'social': {
                    'linkedin': 'https://linkedin.com/in/davidthompson'
                }
            }
        ]),
        'timeline': json.dumps([
            {
                'year': '1993',
                'title': 'Foundation',
                'description': 'Hotel founded with a vision to create a luxury destination. Opened with 50 rooms and a commitment to exceptional service.',
                'image': 'https://images.unsplash.com/photo-1520250497591-112f2f40a3f4?w=800&h=600&fit=crop'
            },
            {
                'year': '2000',
                'title': 'First Expansion',
                'description': 'Expanded to 150 rooms and added our first fine dining restaurant. Received our first five-star rating from international travel guides.',
                'image': 'https://images.unsplash.com/photo-1566073771259-6a8506099945?w=800&h=600&fit=crop'
            },
            {
                'year': '2008',
                'title': 'Spa & Wellness Center',
                'description': 'Opened our world-class spa and wellness center, introducing holistic wellness programs and luxury treatments.',
                'image': 'https://images.unsplash.com/photo-1544161515-4ab6ce6db874?w=800&h=600&fit=crop'
            },
            {
                'year': '2015',
                'title': 'Major Renovation',
                'description': 'Completed a comprehensive renovation, modernizing all rooms and public spaces while preserving our classic elegance.',
                'image': 'https://images.unsplash.com/photo-1618773928121-c32242e63f39?w=800&h=600&fit=crop'
            },
            {
                'year': '2020',
                'title': 'Sustainability Initiative',
                'description': 'Launched our comprehensive sustainability program, achieving carbon neutrality and implementing eco-friendly practices throughout the property.',
                'image': 'https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=800&h=600&fit=crop'
            },
            {
                'year': '2023',
                'title': 'Award Recognition',
                'description': 'Received "Best Luxury Hotel" award and maintained our five-star rating. Celebrated 30 years of excellence in hospitality.',
                'image': 'https://images.unsplash.com/photo-1579621970563-ebec7560ff3e?w=800&h=600&fit=crop'
            }
        ]),
        'achievements': json.dumps([
            {
                'icon': 'trophy',
                'title': 'Best Luxury Hotel 2023',
                'description': 'Awarded by International Hospitality Association',
                'year': '2023',
                'image': 'https://images.unsplash.com/photo-1579621970563-ebec7560ff3e?w=400&h=400&fit=crop'
            },
            {
                'icon': 'star',
                'title': 'Five-Star Rating',
                'description': 'Consistently rated five-star by global travel guides',
                'year': '2020-2023',
                'image': 'https://images.unsplash.com/photo-1579621970563-ebec7560ff3e?w=400&h=400&fit=crop'
            },
            {
                'icon': 'medal',
                'title': 'Excellence in Service',
                'description': 'Recognized for outstanding customer service and guest satisfaction',
                'year': '2022',
                'image': 'https://images.unsplash.com/photo-1579621970563-ebec7560ff3e?w=400&h=400&fit=crop'
            },
            {
                'icon': 'leaf',
                'title': 'Green Hotel Certification',
                'description': 'Certified for sustainable practices and environmental responsibility',
                'year': '2021',
                'image': 'https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05?w=400&h=400&fit=crop'
            },
            {
                'icon': 'users',
                'title': 'Guest Choice Award',
                'description': 'Voted favorite luxury hotel by guests worldwide',
                'year': '2023',
                'image': 'https://images.unsplash.com/photo-1579621970563-ebec7560ff3e?w=400&h=400&fit=crop'
            },
            {
                'icon': 'award',
                'title': 'Culinary Excellence',
                'description': 'Restaurant awarded Michelin star for exceptional cuisine',
                'year': '2022',
                'image': 'https://images.unsplash.com/photo-1414235077428-338989a2e8c0?w=400&h=400&fit=crop'
            }
        ]),
        'stats': json.dumps([
            {'number': '50000+', 'label': 'Happy Guests', 'icon': 'users'},
            {'number': '30+', 'label': 'Years of Excellence', 'icon': 'calendar'},
            {'number': '150+', 'label': 'Awards Won', 'icon': 'award'},
            {'number': '98%', 'label': 'Guest Satisfaction', 'icon': 'star'},
            {'number': '200+', 'label': 'Team Members', 'icon': 'users'},
            {'number': '115', 'label': 'Luxury Rooms', 'icon': 'home'}
        ]),
        'stats_section_title': 'Our Achievements in Numbers',
        'stats_section_subtitle': 'A legacy built on excellence and guest satisfaction',
        'testimonials': json.dumps([
            {
                'name': 'James Wilson',
                'title': 'VIP Guest',
                'quote': 'The level of luxury and attention to detail is simply extraordinary. This hotel understands what true hospitality means.',
                'rating': 5,
                'image': 'https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?w=200&h=200&fit=crop&crop=face'
            },
            {
                'name': 'Sophia Lee',
                'title': 'Travel Blogger',
                'quote': 'Every aspect of my stay was flawless. The service, the amenities, the ambiance - truly a five-star experience.',
                'rating': 5,
                'image': 'https://images.unsplash.com/photo-1438761681033-6461ffad8d80?w=200&h=200&fit=crop&crop=face'
            },
            {
                'name': 'David Chen',
                'title': 'CEO, Global Corp',
                'quote': 'An impeccable hotel with outstanding service. This is what luxury hospitality should be - perfect in every way.',
                'rating': 5,
                'image': 'https://images.unsplash.com/photo-1534528741775-53994a69daeb?w=200&h=200&fit=crop&crop=face'
            },
            {
                'name': 'Maria Garcia',
                'title': 'Frequent Guest',
                'quote': 'I\'ve stayed at many luxury hotels, but this one stands out. The personal attention and genuine care for guests is remarkable.',
                'rating': 5,
                'image': 'https://images.unsplash.com/photo-1544005313-94ddf0286df2?w=200&h=200&fit=crop&crop=face'
            }
        ]),
        'testimonials_section_title': 'What Our Guests Say',
        'testimonials_section_subtitle': 'Stories from our valued guests',
        'gallery_images': json.dumps([
            'https://images.unsplash.com/photo-1520250497591-112f2f40a3f4?w=1200&h=800&fit=crop',
            'https://images.unsplash.com/photo-1566073771259-6a8506099945?w=1200&h=800&fit=crop',
            'https://images.unsplash.com/photo-1618773928121-c32242e63f39?w=1200&h=800&fit=crop',
            'https://images.unsplash.com/photo-1544161515-4ab6ce6db874?w=1200&h=800&fit=crop',
            'https://images.unsplash.com/photo-1414235077428-338989a2e8c0?w=1200&h=800&fit=crop',
            'https://images.unsplash.com/photo-1590490360182-c33d57733427?w=1200&h=800&fit=crop',
            'https://images.unsplash.com/photo-1631049307264-da0ec9d70304?w=1200&h=800&fit=crop',
            'https://images.unsplash.com/photo-1571896349842-33c89424de2d?w=1200&h=800&fit=crop'
        ]),
        'gallery_section_title': 'Our Photo Gallery',
        'gallery_section_subtitle': 'A glimpse into our world of luxury',
        'contact_info': json.dumps({
            'phone': '+1 (555) 123-4567',
            'email': 'info@luxuryhotel.com',
            'address': '123 Luxury Avenue, Premium City, PC 12345'
        }),
        'social_links': json.dumps({
            'facebook': 'https://facebook.com/luxuryhotel',
            'twitter': 'https://twitter.com/luxuryhotel',
            'instagram': 'https://instagram.com/luxuryhotel',
            'linkedin': 'https://linkedin.com/company/luxuryhotel',
            'youtube': 'https://youtube.com/luxuryhotel'
        }),
        'is_active': True,
        'created_at': now,
        'updated_at': now
    }


def seed_about_page(db: Session):
    """Seed about page content into the database"""
    try:
        about_data = get_about_page_data()
        
        # Check if about page content already exists
        existing_content = db.query(PageContent).filter(PageContent.page_type == PageType.ABOUT).first()
        
        if existing_content:
            logger.info('Updating existing about page content...')
            for key, value in about_data.items():
                if key not in ['id', 'page_type', 'created_at']:  # Don't update primary key or creation date
                    setattr(existing_content, key, value)
            existing_content.updated_at = datetime.now(timezone.utc)
        else:
            logger.info('Creating new about page content...')
            about_page = PageContent(**about_data)
            db.add(about_page)
        
        db.commit()
        logger.info('About page content seeded successfully!')
    except Exception as e:
        db.rollback()
        logger.error(f'Error seeding about page: {str(e)}', exc_info=True)
        raise


def main():
    db = SessionLocal()
    try:
        seed_about_page(db)
    except Exception as e:
        logger.error(f'Failed to seed about page: {str(e)}', exc_info=True)
        sys.exit(1)
    finally:
        db.close()


if __name__ == '__main__':
    main()

