from fastapi import APIRouter, Depends, HTTPException from app.services.ai_swarm import AISwarmService from app.models.ai_models import ( AIAnalysisRequest, AIAnalysisResponse, AnalysisFocus, MarketView, InvestmentHorizon ) router = APIRouter() @router.post("/analyze", response_model=AIAnalysisResponse) async def get_ai_recommendations(request: AIAnalysisRequest): """ Get AI-powered investment recommendations based on client profile, portfolio, and goals """ try: ai_service = AISwarmService() result = ai_service.get_enhanced_analysis(request) return result except Exception as e: raise HTTPException(status_code=500, detail=f"Error generating AI recommendations: {str(e)}") @router.post("/fund-selection") async def get_fund_selection_recommendations( client_profile: dict, goals_data: dict, market_conditions: MarketView = MarketView.NEUTRAL, investment_horizon: InvestmentHorizon = InvestmentHorizon.MEDIUM_TERM ): """ Get AI-powered fund selection recommendations """ try: ai_service = AISwarmService() request = AIAnalysisRequest( client_profile=client_profile, portfolio_data={}, goals_data=goals_data, analysis_focus=[AnalysisFocus.FUND_SELECTION], market_conditions=market_conditions, investment_horizon=investment_horizon ) result = ai_service.get_enhanced_analysis(request) return result except Exception as e: raise HTTPException(status_code=500, detail=f"Error generating fund selection recommendations: {str(e)}") @router.post("/risk-assessment") async def get_risk_assessment( client_profile: dict, portfolio_data: dict, market_conditions: MarketView = MarketView.NEUTRAL ): """ Get AI-powered risk assessment for a portfolio """ try: ai_service = AISwarmService() request = AIAnalysisRequest( client_profile=client_profile, portfolio_data=portfolio_data, goals_data={}, analysis_focus=[AnalysisFocus.RISK_ASSESSMENT], market_conditions=market_conditions, investment_horizon=InvestmentHorizon.MEDIUM_TERM ) result = ai_service.get_enhanced_analysis(request) return result except Exception as e: raise HTTPException(status_code=500, detail=f"Error generating risk assessment: {str(e)}") @router.post("/goal-planning") async def get_goal_planning_recommendations( client_profile: dict, goals_data: dict, investment_horizon: InvestmentHorizon = InvestmentHorizon.MEDIUM_TERM ): """ Get AI-powered goal planning recommendations """ try: ai_service = AISwarmService() request = AIAnalysisRequest( client_profile=client_profile, portfolio_data={}, goals_data=goals_data, analysis_focus=[AnalysisFocus.GOAL_ALIGNMENT], market_conditions=MarketView.NEUTRAL, investment_horizon=investment_horizon ) result = ai_service.get_enhanced_analysis(request) return result except Exception as e: raise HTTPException(status_code=500, detail=f"Error generating goal planning recommendations: {str(e)}")