"""
Template Management Package

This package provides a modular approach to template management
functionality with specialized components for better maintainability
and separation of concerns.

Classes:
    TemplateBasicOperations: CRUD operations for templates
    TemplateAnalysis: Step dependency and visibility analysis
    TemplateAutomation: Automation rule management
    TemplateManager: Unified interface combining all functionality
"""

from .base import TemplateManagerBase
from .basic_operations import TemplateBasicOperations
from .analysis import TemplateAnalysis
from .automation import TemplateAutomation


class TemplateManager:
    """
    Unified interface for template management functionality.

    This class provides access to all template management capabilities
    through a single interface while maintaining the modular structure
    underneath.
    """

    def __init__(self, sdk):
        """
        Initialize template manager with SDK instance.

        Args:
            sdk: Main SDK instance
        """
        self.basic_operations = TemplateBasicOperations(sdk)
        self.analysis = TemplateAnalysis(sdk)
        self.automation = TemplateAutomation(sdk)

        # For backward compatibility, expose common methods at the top level
        self.search_templates_by_name = self.basic_operations.search_templates_by_name
        self.get_template = self.basic_operations.get_template
        self.get_all_templates = self.basic_operations.get_all_templates
        self.update_template_metadata = self.basic_operations.update_template_metadata
        self.get_template_with_steps = self.basic_operations.get_template_with_steps
        self.duplicate_template = self.basic_operations.duplicate_template
        self.get_template_steps = self.basic_operations.get_template_steps
        self.edit_description_on_step = self.basic_operations.edit_description_on_step
        self.add_step_to_template = self.basic_operations.add_step_to_template

        # New template lifecycle methods
        self.create_template = self.basic_operations.create_template
        self.delete_template = self.basic_operations.delete_template
        self.delete_step = self.basic_operations.delete_step
        self.clone_step = self.basic_operations.clone_step
        self.reorder_step = self.basic_operations.reorder_step
        self.get_kickoff_form_fields = self.basic_operations.get_kickoff_form_fields

        # Analysis methods
        self.get_step_dependencies = self.analysis.get_step_dependencies
        self.get_step_visibility_conditions = self.analysis.get_step_visibility_conditions

        # Automation methods
        self.create_automation_rule = self.automation.create_automation_rule
        self.update_automation_rule = self.automation.update_automation_rule
        self.delete_automation_rule = self.automation.delete_automation_rule
        self.add_assignees_to_step = self.automation.add_assignees_to_step


# For backward compatibility, create an alias
TemplateManagement = TemplateManager

__all__ = [
    'TemplateManagerBase',
    'TemplateBasicOperations',
    'TemplateAnalysis',
    'TemplateAutomation',
    'TemplateManager',
    'TemplateManagement'  # Backward compatibility alias
]
