"""
FAQ Page Seeder
Seeds the database with comprehensive FAQ content
"""
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_faq_page_data():
    """Generate comprehensive FAQ page data"""
    
    now = datetime.now(timezone.utc)
    
    return {
        'page_type': PageType.FAQ,
        'title': 'Frequently Asked Questions',
        'subtitle': 'Find Answers to Common Questions',
        'description': 'Get answers to the most frequently asked questions about our hotel, reservations, services, and policies.',
        'content': """
            <h2>General Questions</h2>
            
            <h3>What are your check-in and check-out times?</h3>
            <p>Check-in time is 3:00 PM, and check-out time is 11:00 AM. Early check-in and late check-out may be available upon request, subject to availability and additional charges.</p>
            
            <h3>Do you offer airport transportation?</h3>
            <p>Yes, we offer airport transfer services. Please contact our concierge team at least 24 hours in advance to arrange transportation. Additional charges may apply.</p>
            
            <h3>Is parking available?</h3>
            <p>Yes, we offer complimentary valet parking for all hotel guests. Self-parking is also available at an additional charge.</p>
            
            <h3>Do you have a fitness center?</h3>
            <p>Yes, our state-of-the-art fitness center is open 24/7 and is complimentary for all hotel guests. We also offer personal training sessions upon request.</p>
            
            <h3>Is Wi-Fi available?</h3>
            <p>Yes, complimentary high-speed Wi-Fi is available throughout the hotel, including all guest rooms and public areas.</p>
            
            <h2>Reservations & Booking</h2>
            
            <h3>How do I make a reservation?</h3>
            <p>You can make a reservation through our website, by calling our reservations team at +1 (555) 123-4567, or by emailing reservations@luxuryhotel.com.</p>
            
            <h3>Can I modify or cancel my reservation?</h3>
            <p>Yes, you can modify or cancel your reservation through our website or by contacting our reservations team. Please refer to our cancellation policy for details on refunds and fees.</p>
            
            <h3>What payment methods do you accept?</h3>
            <p>We accept all major credit cards (Visa, MasterCard, American Express, Discover), debit cards, and bank transfers. Cash payments are also accepted at check-in.</p>
            
            <h3>Do you require a deposit?</h3>
            <p>A credit card is required to guarantee your reservation. A deposit may be required for certain room types or during peak seasons. Details will be provided at the time of booking.</p>
            
            <h3>Can I book for someone else?</h3>
            <p>Yes, you can make a reservation for another guest. Please provide the guest's name and contact information at the time of booking, and ensure they have a valid ID for check-in.</p>
            
            <h2>Rooms & Accommodations</h2>
            
            <h3>What amenities are included in the rooms?</h3>
            <p>All rooms include complimentary Wi-Fi, flat-screen TV, minibar, coffee maker, in-room safe, air conditioning, and luxury toiletries. Suites include additional amenities such as separate living areas and premium services.</p>
            
            <h3>Do you have connecting rooms?</h3>
            <p>Yes, we have connecting rooms available. Please request connecting rooms at the time of booking, and we will do our best to accommodate your request based on availability.</p>
            
            <h3>Are rooms accessible for guests with disabilities?</h3>
            <p>Yes, we have accessible rooms designed to meet ADA requirements. Please inform us of any specific accessibility needs when making your reservation.</p>
            
            <h3>Can I request a specific room or floor?</h3>
            <p>Yes, you can request a specific room or floor preference. While we cannot guarantee specific rooms, we will do our best to honor your request based on availability.</p>
            
            <h3>Do you allow pets?</h3>
            <p>We welcome service animals. For pets, please contact us in advance as pet-friendly rooms are limited and additional charges may apply.</p>
            
            <h2>Services & Amenities</h2>
            
            <h3>Do you have a spa?</h3>
            <p>Yes, we have a world-class spa offering a variety of treatments. Advance reservations are recommended. Please contact our spa directly to book treatments.</p>
            
            <h3>Are there restaurants on-site?</h3>
            <p>Yes, we have multiple dining options including fine dining, casual restaurants, and room service available 24/7. Our restaurants feature award-winning cuisine and extensive wine selections.</p>
            
            <h3>Do you offer room service?</h3>
            <p>Yes, room service is available 24 hours a day. Our extensive menu includes breakfast, lunch, dinner, and late-night options.</p>
            
            <h3>Is there a business center?</h3>
            <p>Yes, our business center is equipped with computers, printers, and meeting facilities. It is available 24/7 for all guests.</p>
            
            <h3>Do you have meeting and event facilities?</h3>
            <p>Yes, we have versatile meeting and event spaces suitable for conferences, weddings, and other special occasions. Please contact our events team for more information.</p>
            
            <h2>Policies & Procedures</h2>
            
            <h3>What is your cancellation policy?</h3>
            <p>Cancellation policies vary by rate type and booking. Generally, cancellations made 24-48 hours before check-in are free. Please refer to your booking confirmation for specific cancellation terms.</p>
            
            <h3>What is your smoking policy?</h3>
            <p>Our hotel is 100% non-smoking. Smoking is not permitted in any guest rooms or indoor public areas. Designated outdoor smoking areas are available.</p>
            
            <h3>What is the minimum age to check in?</h3>
            <p>Guests must be at least 18 years old to check in. Guests under 18 must be accompanied by an adult.</p>
            
            <h3>Do you have a lost and found?</h3>
            <p>Yes, we maintain a lost and found department. If you have lost an item, please contact our front desk immediately. We will make every effort to locate and return your belongings.</p>
            
            <h2>Special Requests</h2>
            
            <h3>Can I request early check-in or late check-out?</h3>
            <p>Early check-in and late check-out are subject to availability. Please contact us in advance, and we will do our best to accommodate your request. Additional charges may apply.</p>
            
            <h3>Do you accommodate special dietary requirements?</h3>
            <p>Yes, we can accommodate various dietary requirements including vegetarian, vegan, gluten-free, and allergies. Please inform us of any dietary restrictions when making your reservation or dining reservation.</p>
            
            <h3>Can you help arrange special occasions?</h3>
            <p>Absolutely! Our concierge team can help arrange special occasions such as anniversaries, birthdays, or proposals. Please contact us in advance to discuss your needs.</p>
            
            <h2>Contact & Support</h2>
            
            <h3>How can I contact the hotel?</h3>
            <p>You can reach us by phone at +1 (555) 123-4567, email at info@luxuryhotel.com, or through our website's contact form. Our front desk is available 24/7.</p>
            
            <h3>Do you have a loyalty program?</h3>
            <p>Yes, we offer a loyalty program with exclusive benefits including room upgrades, late check-out, and special rates. Membership is free. Please visit our website or contact us for more information.</p>
            
            <h3>Can I leave feedback about my stay?</h3>
            <p>We value your feedback! You can leave a review on our website, through our post-stay survey, or by contacting our guest relations team directly.</p>
        """,
        'meta_title': 'FAQ | Frequently Asked Questions - Luxury Hotel & Resort',
        'meta_description': 'Find answers to frequently asked questions about reservations, rooms, services, and policies at Luxury Hotel & Resort.',
        'meta_keywords': 'FAQ, frequently asked questions, hotel questions, booking questions, hotel policies, hotel information',
        'og_title': 'FAQ - Luxury Hotel & Resort',
        'og_description': 'Find answers to common questions about our hotel, reservations, and services.',
        'og_image': 'https://images.unsplash.com/photo-1556761175-5973dc0f32e7?w=1200&h=630&fit=crop',
        'canonical_url': 'https://luxuryhotel.com/faq',
        'is_active': True,
        'created_at': now,
        'updated_at': now
    }


def seed_faq_page(db: Session):
    """Seed FAQ page content into the database"""
    try:
        faq_data = get_faq_page_data()
        
        # Check if FAQ page content already exists
        existing_content = db.query(PageContent).filter(PageContent.page_type == PageType.FAQ).first()
        
        if existing_content:
            logger.info('Updating existing FAQ page content...')
            for key, value in faq_data.items():
                if key not in ['id', 'page_type', 'created_at']:
                    setattr(existing_content, key, value)
            existing_content.updated_at = datetime.now(timezone.utc)
        else:
            logger.info('Creating new FAQ page content...')
            faq_page = PageContent(**faq_data)
            db.add(faq_page)
        
        db.commit()
        logger.info('FAQ page content seeded successfully!')
    except Exception as e:
        db.rollback()
        logger.error(f'Error seeding FAQ page: {str(e)}', exc_info=True)
        raise


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


if __name__ == '__main__':
    main()

