"""Default template definitions for spec documentation."""

from .config import TemplateConfig

# Default template content with comprehensive structure
DEFAULT_INDEX_TEMPLATE = """# {{filename}}

**Location**: `{{filepath}}`
**Type**: {{file_type}}
**Last Updated**: {{date}}

## Purpose

{{purpose}}

## Overview

{{overview}}

## Key Responsibilities

{{responsibilities}}

## Dependencies

{{dependencies}}

## API/Interface

{{api_interface}}

## Usage Examples

```{{file_extension}}
{{example_usage}}
```

## Configuration

{{configuration}}

## Error Handling

{{error_handling}}

## Testing

{{testing_notes}}

## Performance Considerations

{{performance_notes}}

## Security Considerations

{{security_notes}}

## Future Enhancements

{{future_enhancements}}

## Related Documentation

{{related_docs}}

## Notes

{{notes}}

---
*Generated by spec-cli on {{date}}*
"""

DEFAULT_HISTORY_TEMPLATE = """# History for {{filename}}

This file tracks the evolution, changes, and lessons learned for `{{filepath}}`.

## {{date}} - Initial Creation

**Context**: {{context}}

**Purpose**: {{initial_purpose}}

**Key Decisions**: {{decisions}}

**Implementation Notes**: {{implementation_notes}}

## Change Log

### Format
Each entry should include:
- **Date**: When the change occurred
- **Type**: [Feature|Bugfix|Refactor|Documentation|Performance|Security]
- **Description**: What changed and why
- **Impact**: How this affects the codebase
- **Lessons Learned**: What we learned from this change

---

## Templates for Future Entries

### Feature Addition
```
## YYYY-MM-DD - Feature: [Brief Description]

**Type**: Feature
**Description**: [Detailed description of the feature]
**Motivation**: [Why this feature was needed]
**Implementation**: [How it was implemented]
**Impact**: [Effects on the codebase, performance, etc.]
**Lessons Learned**: [What we learned during implementation]
```

### Bug Fix
```
## YYYY-MM-DD - Bugfix: [Brief Description]

**Type**: Bugfix
**Description**: [What bug was fixed]
**Root Cause**: [What caused the bug]
**Solution**: [How the bug was fixed]
**Prevention**: [How to prevent similar bugs]
**Lessons Learned**: [What we learned from this bug]
```

### Refactoring
```
## YYYY-MM-DD - Refactor: [Brief Description]

**Type**: Refactor
**Description**: [What was refactored]
**Motivation**: [Why the refactor was needed]
**Changes**: [What specifically changed]
**Benefits**: [Improvements gained]
**Lessons Learned**: [What we learned during refactoring]
```

---
*History maintained by spec-cli*
"""


def get_default_template_config() -> TemplateConfig:
    """Get the default template configuration.

    Returns:
        TemplateConfig with default templates
    """
    return TemplateConfig(
        index=DEFAULT_INDEX_TEMPLATE, history=DEFAULT_HISTORY_TEMPLATE
    )


def get_minimal_template_config() -> TemplateConfig:
    """Get a minimal template configuration for quick documentation.

    Returns:
        TemplateConfig with minimal templates
    """
    minimal_index = """# {{filename}}

**Location**: {{filepath}}
**Purpose**: {{purpose}}

## Overview

{{overview}}

## Usage

```{{file_extension}}
{{example_usage}}
```

## Notes

{{notes}}
"""

    minimal_history = """# History for {{filename}}

**Location**: {{filepath}}

## {{date}} - Initial Creation

**Purpose**: {{initial_purpose}}
**Context**: {{context}}
"""

    return TemplateConfig(index=minimal_index, history=minimal_history)


def get_comprehensive_template_config() -> TemplateConfig:
    """Get a comprehensive template configuration for detailed documentation.

    Returns:
        TemplateConfig with comprehensive templates
    """
    comprehensive_index = (
        DEFAULT_INDEX_TEMPLATE
        + """

## Architecture

{{architecture}}

## Design Patterns

{{design_patterns}}

## Code Quality

{{code_quality}}

## Monitoring

{{monitoring}}

## Troubleshooting

{{troubleshooting}}

## Migration Guide

{{migration_guide}}
"""
    )

    comprehensive_history = (
        DEFAULT_HISTORY_TEMPLATE
        + """

## Detailed Analysis

### Architecture Evolution
{{architecture_evolution}}

### Performance Impact
{{performance_impact}}

### Security Implications
{{security_implications}}

### Technical Debt
{{technical_debt}}

### Future Planning
{{future_planning}}
"""
    )

    return TemplateConfig(index=comprehensive_index, history=comprehensive_history)


# Template configurations registry
TEMPLATE_PRESETS = {
    "default": get_default_template_config,
    "minimal": get_minimal_template_config,
    "comprehensive": get_comprehensive_template_config,
}


def get_template_preset(preset_name: str) -> TemplateConfig:
    """Get a template configuration by preset name.

    Args:
        preset_name: Name of the preset ("default", "minimal", "comprehensive")

    Returns:
        TemplateConfig for the preset

    Raises:
        ValueError: If preset name is not recognized
    """
    if preset_name not in TEMPLATE_PRESETS:
        available = ", ".join(TEMPLATE_PRESETS.keys())
        raise ValueError(
            f"Unknown template preset '{preset_name}'. Available: {available}"
        )

    return TEMPLATE_PRESETS[preset_name]()
