from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from routers import algorithms, events, devices
from core.database import engine
from models.base import Base

# 创建数据库表
Base.metadata.create_all(bind=engine)

app = FastAPI(
    title="边检CV算法接口服务",
    description="边检计算机视觉算法管理系统API",
    version="1.0.0"
)

# 配置CORS
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],  # 生产环境中应该指定具体域名
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# 注册路由
app.include_router(algorithms.router, prefix="/api/algorithms", tags=["算法管理"])
app.include_router(events.router, prefix="/api/events", tags=["事件管理"])
app.include_router(devices.router, prefix="/api/devices", tags=["设备管理"])

@app.get("/")
async def root():
    return {"message": "边检CV算法接口服务"}

@app.get("/health")
async def health_check():
    return {"status": "healthy"}

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000, reload=True, workers=10) 