"""
Accessibility Page Seeder
Seeds the database with comprehensive accessibility information
"""
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_accessibility_page_data():
    """Generate comprehensive accessibility page data"""
    
    now = datetime.now(timezone.utc)
    
    return {
        'page_type': PageType.ACCESSIBILITY,
        'title': 'Accessibility',
        'subtitle': 'Committed to Accessibility for All',
        'description': 'We are committed to providing accessible facilities and services for all our guests. Learn about our accessibility features and accommodations.',
        'content': """
            <h2>Our Commitment to Accessibility</h2>
            <p>At Luxury Hotel & Resort, we are committed to ensuring that our facilities and services are accessible to all guests, including those with disabilities. We strive to comply with the Americans with Disabilities Act (ADA) and continuously work to improve accessibility throughout our property.</p>
            
            <h2>Accessible Accommodations</h2>
            <h3>Accessible Guest Rooms</h3>
            <p>We offer several accessible guest rooms designed to meet ADA requirements, featuring:</p>
            <ul>
                <li>Wider doorways (minimum 32 inches)</li>
                <li>Roll-in showers or accessible bathtubs with grab bars</li>
                <li>Lowered light switches and thermostats</li>
                <li>Visual door knockers and phone alerts</li>
                <li>Accessible vanities and bathroom fixtures</li>
                <li>Closed-captioned televisions</li>
                <li>Accessible closet rods and shelves</li>
            </ul>
            
            <h3>Room Features</h3>
            <ul>
                <li>Hearing-impaired kits available upon request</li>
                <li>Visual smoke detectors</li>
                <li>TTY/TDD devices available</li>
                <li>Accessible furniture and seating</li>
            </ul>
            
            <h2>Public Areas & Facilities</h2>
            <h3>Entrance & Lobby</h3>
            <ul>
                <li>Wheelchair-accessible main entrance</li>
                <li>Automatic doors at main entrance</li>
                <li>Accessible front desk with lowered counter</li>
                <li>Accessible seating areas in lobby</li>
            </ul>
            
            <h3>Dining Facilities</h3>
            <ul>
                <li>Accessible dining areas in all restaurants</li>
                <li>Accessible tables and seating</li>
                <li>Menus available in large print or braille upon request</li>
                <li>Staff trained to assist guests with disabilities</li>
            </ul>
            
            <h3>Recreation & Fitness</h3>
            <ul>
                <li>Accessible fitness center with adaptive equipment</li>
                <li>Accessible pool area with pool lift (available upon request)</li>
                <li>Accessible spa facilities</li>
            </ul>
            
            <h3>Meeting & Event Spaces</h3>
            <ul>
                <li>Accessible meeting rooms</li>
                <li>Accessible restrooms in meeting areas</li>
                <li>Assistive listening devices available</li>
                <li>Sign language interpreters available with advance notice</li>
            </ul>
            
            <h2>Parking & Transportation</h2>
            <ul>
                <li>Accessible parking spaces near main entrance</li>
                <li>Van-accessible parking spaces</li>
                <li>Accessible valet service</li>
                <li>Accessible transportation available upon request</li>
            </ul>
            
            <h2>Service Animals</h2>
            <p>Service animals are welcome throughout our property. We comply with all applicable laws regarding service animals and do not charge additional fees for service animals.</p>
            
            <h2>Assistive Devices & Services</h2>
            <h3>Available Upon Request</h3>
            <ul>
                <li>TTY/TDD devices</li>
                <li>Visual door knockers</li>
                <li>Hearing-impaired kits</li>
                <li>Closed-captioned televisions</li>
                <li>Large print menus and materials</li>
                <li>Braille materials (available for select items)</li>
                <li>Assistive listening devices for meetings</li>
                <li>Sign language interpreters (with advance notice)</li>
            </ul>
            
            <h2>Website Accessibility</h2>
            <p>We are committed to making our website accessible to all users. Our website is designed to comply with WCAG 2.1 Level AA standards. If you encounter any accessibility barriers on our website, please contact us so we can address the issue.</p>
            
            <h2>Communication</h2>
            <p>Our staff is trained to communicate effectively with guests who have disabilities. We can provide information in alternative formats upon request, including:</p>
            <ul>
                <li>Large print materials</li>
                <li>Written materials</li>
                <li>Assistance with reading menus or other materials</li>
            </ul>
            
            <h2>Accessibility Concerns & Feedback</h2>
            <p>We welcome feedback from our guests regarding accessibility. If you have any concerns or suggestions for improvement, please contact us:</p>
            <ul>
                <li><strong>Email:</strong> accessibility@luxuryhotel.com</li>
                <li><strong>Phone:</strong> +1 (555) 123-4567</li>
                <li><strong>TTY/TDD:</strong> +1 (555) 123-4568</li>
                <li><strong>Address:</strong> 123 Luxury Avenue, Premium City, PC 12345, United States</li>
            </ul>
            
            <h2>Reservations</h2>
            <p>When making a reservation, please inform us of any specific accessibility needs so we can ensure your room and services meet your requirements. Our reservations team is available 24/7 to assist you.</p>
            <ul>
                <li><strong>Reservations Phone:</strong> +1 (555) 123-4567</li>
                <li><strong>Reservations Email:</strong> reservations@luxuryhotel.com</li>
            </ul>
            
            <h2>Ongoing Improvements</h2>
            <p>We are continuously working to improve accessibility throughout our property. We regularly review and update our facilities and services to better serve all our guests. If you have suggestions for improvements, we would love to hear from you.</p>
            
            <p><em>Last Updated: {}</em></p>
        """.format(now.strftime('%B %d, %Y')),
        'meta_title': 'Accessibility | Luxury Hotel & Resort - Accessible Facilities',
        'meta_description': 'Learn about our accessible facilities and services. We are committed to providing accessible accommodations for all guests.',
        'meta_keywords': 'accessibility, ADA, accessible hotel, wheelchair accessible, disability accommodations, accessible rooms',
        'og_title': 'Accessibility - Luxury Hotel & Resort',
        'og_description': 'Committed to accessibility for all. Learn about our accessible facilities and services.',
        'og_image': 'https://images.unsplash.com/photo-1556761175-5973dc0f32e7?w=1200&h=630&fit=crop',
        'canonical_url': 'https://luxuryhotel.com/accessibility',
        'is_active': True,
        'created_at': now,
        'updated_at': now
    }


def seed_accessibility_page(db: Session):
    """Seed accessibility page content into the database"""
    try:
        accessibility_data = get_accessibility_page_data()
        
        # Check if accessibility page content already exists
        existing_content = db.query(PageContent).filter(PageContent.page_type == PageType.ACCESSIBILITY).first()
        
        if existing_content:
            logger.info('Updating existing accessibility page content...')
            for key, value in accessibility_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 accessibility page content...')
            accessibility_page = PageContent(**accessibility_data)
            db.add(accessibility_page)
        
        db.commit()
        logger.info('Accessibility page content seeded successfully!')
    except Exception as e:
        db.rollback()
        logger.error(f'Error seeding accessibility page: {str(e)}', exc_info=True)
        raise


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


if __name__ == '__main__':
    main()

