"""
Template Configuration Examples for PrecipGen Convenience API.

This module provides example configurations for different report types and use cases,
demonstrating how to customize the appearance and content of generated reports.
"""

from precipgen.convenience.config import TemplateConfig

# Example 1: Scientific Publication Template
SCIENTIFIC_TEMPLATE = TemplateConfig(
    template_name="scientific_report",
    output_format="html",
    include_executive_summary=True,
    include_trend_analysis=True,
    include_validation_details=True,
    include_plots=True,
    embed_plots=False,  # Keep plots as separate files for publication
    include_raw_data=False,
    date_format="%B %d, %Y",
    filename_pattern="{location}_scientific_analysis_{date}",
    custom_variables={
        "author": "PrecipGen Analysis System",
        "institution": "Climate Research Laboratory",
        "report_type": "Scientific Analysis",
        "methodology": "Richardson & Wright (1984) WGEN Algorithm"
    },
    custom_css="""
        .citation { font-style: italic; color: #666; }
        .equation { background: #f8f9fa; padding: 10px; margin: 15px 0; }
        .methodology { border-left: 4px solid #007acc; }
    """,
    custom_header="""
        <div style="text-align: center; padding: 10px; background: #f0f0f0; margin-bottom: 20px;">
            <strong>CONFIDENTIAL RESEARCH REPORT</strong><br>
            <small>For Internal Use Only</small>
        </div>
    """
)

# Example 2: Engineering Consulting Template
ENGINEERING_TEMPLATE = TemplateConfig(
    template_name="engineering_report",
    output_format="html",
    include_executive_summary=True,
    include_trend_analysis=True,
    include_validation_details=True,
    include_plots=True,
    embed_plots=True,  # Embed for self-contained reports
    include_raw_data=False,
    date_format="%m/%d/%Y",
    filename_pattern="{location}_engineering_parameters_{timestamp}",
    custom_variables={
        "company": "Hydro Engineering Consultants",
        "project_number": "HEC-2024-001",
        "client": "Municipal Water Authority",
        "engineer": "Licensed Professional Engineer",
        "report_class": "Engineering Analysis"
    },
    custom_css="""
        .stamp { 
            position: fixed; 
            top: 20px; 
            right: 20px; 
            background: #e74c3c; 
            color: white; 
            padding: 10px; 
            transform: rotate(15deg); 
            font-weight: bold;
        }
        .design-table th { background: #2c3e50; color: white; }
        .recommendation-box { border-left: 5px solid #27ae60; }
    """,
    custom_footer="""
        <div style="text-align: center; margin-top: 20px; font-size: 0.9em;">
            <p><strong>This report prepared by licensed professional engineers</strong></p>
            <p>Seal and signature on file | Report valid for 2 years from date of issue</p>
        </div>
    """
)

# Example 3: Minimal Dashboard Template
MINIMAL_TEMPLATE = TemplateConfig(
    template_name="minimal_report",
    output_format="html",
    include_executive_summary=False,
    include_trend_analysis=True,
    include_validation_details=False,
    include_plots=True,
    embed_plots=True,
    include_raw_data=False,
    date_format="%Y-%m-%d",
    filename_pattern="{location}_summary",
    custom_variables={
        "report_style": "minimal",
        "focus": "key_metrics_only"
    }
)

# Example 4: Comprehensive Research Template
COMPREHENSIVE_TEMPLATE = TemplateConfig(
    template_name="default_report",
    output_format="html",
    include_executive_summary=True,
    include_trend_analysis=True,
    include_validation_details=True,
    include_plots=True,
    embed_plots=False,
    include_raw_data=True,
    date_format="%B %d, %Y at %I:%M %p",
    filename_pattern="{location}_comprehensive_analysis_{station_id}_{timestamp}",
    custom_variables={
        "analysis_level": "comprehensive",
        "quality_assurance": "peer_reviewed",
        "data_source": "GHCN-Daily Database",
        "algorithm": "WGEN (Richardson & Wright, 1984)"
    },
    custom_css="""
        .section { 
            border: 1px solid #ddd; 
            margin-bottom: 30px; 
            box-shadow: 0 2px 5px rgba(0,0,0,0.1); 
        }
        .trend-summary { 
            background: linear-gradient(135deg, #e8f4fd 0%, #f0f8ff 100%); 
        }
        .validation-summary { 
            background: linear-gradient(135deg, #f0f8f0 0%, #f8fff8 100%); 
        }
    """
)

# Example 5: Batch Processing Template
BATCH_TEMPLATE = TemplateConfig(
    template_name="batch_summary",
    output_format="html",
    include_executive_summary=True,
    include_trend_analysis=True,
    include_validation_details=False,
    include_plots=True,
    embed_plots=True,
    include_raw_data=False,
    date_format="%Y-%m-%d %H:%M UTC",
    filename_pattern="batch_analysis_{timestamp}",
    custom_variables={
        "analysis_type": "regional_batch",
        "processing_mode": "automated",
        "quality_control": "automated_validation"
    }
)

# Example 6: Custom Branded Template
CUSTOM_BRANDED_TEMPLATE = TemplateConfig(
    template_name="default_report",
    output_format="html",
    include_executive_summary=True,
    include_trend_analysis=True,
    include_validation_details=True,
    include_plots=True,
    embed_plots=True,
    include_raw_data=False,
    date_format="%B %d, %Y",
    filename_pattern="{location}_climate_analysis",
    custom_variables={
        "organization": "Climate Analytics Corporation",
        "logo_url": "/assets/company_logo.png",
        "contact_info": "info@climateanalytics.com",
        "website": "www.climateanalytics.com"
    },
    custom_css="""
        .header {
            background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
            color: white;
            position: relative;
        }
        .header::before {
            content: '';
            position: absolute;
            top: 10px;
            right: 20px;
            width: 60px;
            height: 60px;
            background: url('/assets/company_logo.png') no-repeat center;
            background-size: contain;
        }
        .section h2 {
            color: #1e3c72;
            border-bottom: 2px solid #2a5298;
        }
        .footer {
            background: #1e3c72;
            color: white;
        }
    """,
    custom_header="""
        <div style="background: #f8f9fa; padding: 15px; text-align: center; border-bottom: 3px solid #1e3c72;">
            <h3 style="margin: 0; color: #1e3c72;">Climate Analytics Corporation</h3>
            <p style="margin: 5px 0 0 0; color: #666;">Professional Climate Analysis Services</p>
        </div>
    """,
    custom_footer="""
        <div style="text-align: center; padding: 20px; background: #1e3c72; color: white; margin-top: 30px;">
            <p><strong>Climate Analytics Corporation</strong></p>
            <p>📧 info@climateanalytics.com | 🌐 www.climateanalytics.com | 📞 (555) 123-4567</p>
            <p><small>This analysis is provided under our standard terms of service. 
            Results are based on historical data and statistical modeling.</small></p>
        </div>
    """
)

# Template selection helper function
def get_template_config(template_type: str = "default") -> TemplateConfig:
    """
    Get a pre-configured template based on use case.
    
    Args:
        template_type: Type of template to retrieve
            - "scientific": For academic/research publications
            - "engineering": For engineering consulting reports
            - "minimal": For quick summaries and dashboards
            - "comprehensive": For detailed research analysis
            - "batch": For batch processing summaries
            - "branded": For custom branded reports
            - "default": Standard template
    
    Returns:
        TemplateConfig instance for the specified type
    """
    templates = {
        "scientific": SCIENTIFIC_TEMPLATE,
        "engineering": ENGINEERING_TEMPLATE,
        "minimal": MINIMAL_TEMPLATE,
        "comprehensive": COMPREHENSIVE_TEMPLATE,
        "batch": BATCH_TEMPLATE,
        "branded": CUSTOM_BRANDED_TEMPLATE,
        "default": TemplateConfig()  # Default configuration
    }
    
    return templates.get(template_type, TemplateConfig())

# Usage examples for different scenarios
USAGE_EXAMPLES = {
    "academic_research": {
        "description": "Academic research paper with full methodology and citations",
        "template": SCIENTIFIC_TEMPLATE,
        "use_case": "Publishing climate trend analysis in peer-reviewed journals"
    },
    
    "consulting_project": {
        "description": "Professional engineering report for client deliverable",
        "template": ENGINEERING_TEMPLATE,
        "use_case": "Hydrological design parameters for infrastructure projects"
    },
    
    "quick_assessment": {
        "description": "Rapid climate assessment for preliminary analysis",
        "template": MINIMAL_TEMPLATE,
        "use_case": "Initial site evaluation and feasibility studies"
    },
    
    "comprehensive_study": {
        "description": "Detailed analysis with all available information",
        "template": COMPREHENSIVE_TEMPLATE,
        "use_case": "Complete climate characterization for major projects"
    },
    
    "regional_analysis": {
        "description": "Multi-location batch analysis with regional patterns",
        "template": BATCH_TEMPLATE,
        "use_case": "Regional climate assessment across multiple sites"
    },
    
    "branded_report": {
        "description": "Custom branded report for client presentation",
        "template": CUSTOM_BRANDED_TEMPLATE,
        "use_case": "Professional client deliverables with company branding"
    }
}

def demonstrate_template_usage():
    """
    Demonstrate how to use different template configurations.
    
    This function shows example code for using various template types
    with the PrecipGen Convenience API.
    """
    
    examples = """
    # Example 1: Scientific Research Report
    from precipgen.convenience import ConvenienceAPI
    from precipgen.convenience.templates.template_examples import get_template_config
    
    api = ConvenienceAPI()
    scientific_config = get_template_config("scientific")
    
    result = api.analyze_precipitation(
        location="Seattle, WA",
        template_config=scientific_config
    )
    
    # Example 2: Engineering Consulting Report
    engineering_config = get_template_config("engineering")
    engineering_config.custom_variables.update({
        "project_number": "HYD-2024-042",
        "client": "City of Seattle",
        "engineer": "Jane Smith, P.E."
    })
    
    result = api.analyze_precipitation(
        location="Seattle, WA",
        template_config=engineering_config
    )
    
    # Example 3: Batch Analysis with Custom Branding
    from precipgen.convenience import BatchProcessor
    
    batch_config = get_template_config("batch")
    batch_config.custom_variables["organization"] = "Regional Water Authority"
    
    processor = BatchProcessor()
    locations = ["Seattle, WA", "Portland, OR", "Vancouver, BC"]
    
    batch_results = processor.analyze_multiple_locations(
        locations=locations,
        template_config=batch_config
    )
    
    # Example 4: Minimal Report for Dashboard
    minimal_config = get_template_config("minimal")
    
    result = api.analyze_precipitation(
        location="Seattle, WA",
        template_config=minimal_config
    )
    
    # Example 5: Custom Template Configuration
    custom_config = TemplateConfig(
        template_name="engineering_report",
        custom_variables={
            "company": "Your Company Name",
            "project": "Project XYZ",
            "date": "2024"
        },
        custom_css='''
            .header { background: #your-brand-color; }
            .section h2 { color: #your-brand-color; }
        ''',
        embed_plots=True,
        include_executive_summary=True
    )
    
    result = api.analyze_precipitation(
        location="Your Location",
        template_config=custom_config
    )
    """
    
    return examples

if __name__ == "__main__":
    # Print available templates and their descriptions
    print("Available PrecipGen Report Templates:")
    print("=" * 50)
    
    for name, example in USAGE_EXAMPLES.items():
        print(f"\n{name.upper()}:")
        print(f"  Description: {example['description']}")
        print(f"  Use Case: {example['use_case']}")
        print(f"  Template: {example['template'].template_name}")
    
    print("\n" + "=" * 50)
    print("Usage Examples:")
    print(demonstrate_template_usage())