"""
Goal Tracking System - Set and pursue long-term objectives
"""
from typing import List, Dict, Any
import time

class GoalTracker:
    def __init__(self):
        self.goals = []
        self.completed_goals = []
        
    def set_goal(self, description: str, priority: int = 5) -> Dict[str, Any]:
        """Set a new goal"""
        goal = {
            'id': len(self.goals),
            'description': description,
            'priority': priority,
            'created': time.time(),
            'progress': 0.0,
            'status': 'active'
        }
        self.goals.append(goal)
        return goal
    
    def update_progress(self, goal_id: int, progress: float):
        """Update goal progress"""
        for goal in self.goals:
            if goal['id'] == goal_id:
                goal['progress'] = min(1.0, max(0.0, progress))
                if goal['progress'] >= 1.0:
                    goal['status'] = 'completed'
                    self.completed_goals.append(goal)
                    self.goals.remove(goal)
    
    def get_active_goals(self) -> List[Dict[str, Any]]:
        """Get all active goals sorted by priority"""
        return sorted(self.goals, key=lambda x: x['priority'], reverse=True)
