"""Integration management endpoints.""" from typing import List, Dict, Any from fastapi import APIRouter, HTTPException from pydantic import BaseModel router = APIRouter() class IntegrationCreate(BaseModel): name: str type: str # gitea, jira_fixer, github, etc base_url: str api_token: str enabled: bool = True class IntegrationRead(BaseModel): id: int name: str type: str base_url: str enabled: bool last_sync: str = None # Mock data for now (will use database later) INTEGRATIONS: List[Dict[str, Any]] = [ { "id": 1, "name": "JIRA AI Fixer", "type": "jira_fixer", "base_url": "https://jira-fixer.startdata.com.br", "enabled": True, "last_sync": None } ] @router.get("/", response_model=List[IntegrationRead]) async def list_integrations(): """List all integrations.""" return INTEGRATIONS @router.post("/", response_model=IntegrationRead, status_code=201) async def create_integration(integration: IntegrationCreate): """Create new integration.""" new_id = max([i["id"] for i in INTEGRATIONS], default=0) + 1 new_integration = { "id": new_id, "name": integration.name, "type": integration.type, "base_url": integration.base_url, "enabled": integration.enabled, "last_sync": None } INTEGRATIONS.append(new_integration) return new_integration @router.get("/{integration_id}", response_model=IntegrationRead) async def get_integration(integration_id: int): """Get integration by ID.""" for integration in INTEGRATIONS: if integration["id"] == integration_id: return integration raise HTTPException(status_code=404, detail="Integration not found") @router.delete("/{integration_id}") async def delete_integration(integration_id: int): """Delete integration.""" global INTEGRATIONS INTEGRATIONS = [i for i in INTEGRATIONS if i["id"] != integration_id] return {"message": "Integration deleted"}