#!/usr/bin/python
# -*- coding: utf-8 -*-
# @version        : 1.0
# @Create Time    : 2025/04/03 10:30
# @File           : views.py
# @IDE            : PyCharm
# @desc           : 路由，视图文件
from core.dependencies import IdList
from apps.vadmin.auth.utils.validation.auth import Auth
from sqlalchemy.ext.asyncio import AsyncSession
from apps.vadmin.auth.utils.current import AllUserAuth
from core.database import db_getter
from . import schemas, crud, models, params
from fastapi import Depends, APIRouter
from utils.response import SuccessResponse



app = APIRouter()


###########################################################
#    项目推理集合信息
###########################################################
@app.get("/project/detect", summary="获取项目推理集合信息列表", tags=["项目推理集合信息"])
async def get_project_detect_list(p: params.ProjectDetectParams = Depends(), auth: Auth = Depends(AllUserAuth())):
    datas, count = await crud.ProjectDetectDal(auth.db).get_datas(**p.dict(), v_return_count=True)
    return SuccessResponse(datas, count=count)


@app.post("/project/detect", summary="创建项目推理集合信息", tags=["项目推理集合信息"])
async def create_project_detect(data: schemas.ProjectDetect, auth: Auth = Depends(AllUserAuth())):
    return SuccessResponse(await crud.ProjectDetectDal(auth.db).create_data(data=data))


@app.delete("/project/detect", summary="删除项目推理集合信息", description="硬删除", tags=["项目推理集合信息"])
async def delete_project_detect_list(ids: IdList = Depends(), auth: Auth = Depends(AllUserAuth())):
    await crud.ProjectDetectDal(auth.db).delete_datas(ids=ids.ids, v_soft=False)
    return SuccessResponse("删除成功")


@app.put("/project/detect/{data_id}", summary="更新项目推理集合信息", tags=["项目推理集合信息"])
async def put_project_detect(data_id: int, data: schemas.ProjectDetect, auth: Auth = Depends(AllUserAuth())):
    return SuccessResponse(await crud.ProjectDetectDal(auth.db).put_data(data_id, data))


@app.get("/project/detect/{data_id}", summary="获取项目推理集合信息信息", tags=["项目推理集合信息"])
async def get_project_detect(data_id: int, db: AsyncSession = Depends(db_getter)):
    schema = schemas.ProjectDetectSimpleOut
    return SuccessResponse(await crud.ProjectDetectDal(db).get_data(data_id, v_schema=schema))




###########################################################
#    项目推理集合图片信息
###########################################################
@app.get("/project/detect/img", summary="获取项目推理集合图片信息列表", tags=["项目推理集合图片信息"])
async def get_project_detect_img_list(p: params.ProjectDetectImgParams = Depends(), auth: Auth = Depends(AllUserAuth())):
    datas, count = await crud.ProjectDetectImgDal(auth.db).get_datas(**p.dict(), v_return_count=True)
    return SuccessResponse(datas, count=count)


@app.post("/project/detect/img", summary="创建项目推理集合图片信息", tags=["项目推理集合图片信息"])
async def create_project_detect_img(data: schemas.ProjectDetectImg, auth: Auth = Depends(AllUserAuth())):
    return SuccessResponse(await crud.ProjectDetectImgDal(auth.db).create_data(data=data))


@app.delete("/project/detect/img", summary="删除项目推理集合图片信息", description="硬删除", tags=["项目推理集合图片信息"])
async def delete_project_detect_img_list(ids: IdList = Depends(), auth: Auth = Depends(AllUserAuth())):
    await crud.ProjectDetectImgDal(auth.db).delete_datas(ids=ids.ids, v_soft=False)
    return SuccessResponse("删除成功")


@app.put("/project/detect/img/{data_id}", summary="更新项目推理集合图片信息", tags=["项目推理集合图片信息"])
async def put_project_detect_img(data_id: int, data: schemas.ProjectDetectImg, auth: Auth = Depends(AllUserAuth())):
    return SuccessResponse(await crud.ProjectDetectImgDal(auth.db).put_data(data_id, data))


@app.get("/project/detect/img/{data_id}", summary="获取项目推理集合图片信息信息", tags=["项目推理集合图片信息"])
async def get_project_detect_img(data_id: int, db: AsyncSession = Depends(db_getter)):
    schema = schemas.ProjectDetectImgSimpleOut
    return SuccessResponse(await crud.ProjectDetectImgDal(db).get_data(data_id, v_schema=schema))




###########################################################
#    项目推理记录信息
###########################################################
@app.get("/project/detect/log", summary="获取项目推理记录信息列表", tags=["项目推理记录信息"])
async def get_project_detect_log_list(p: params.ProjectDetectLogParams = Depends(), auth: Auth = Depends(AllUserAuth())):
    datas, count = await crud.ProjectDetectLogDal(auth.db).get_datas(**p.dict(), v_return_count=True)
    return SuccessResponse(datas, count=count)


@app.post("/project/detect/log", summary="创建项目推理记录信息", tags=["项目推理记录信息"])
async def create_project_detect_log(data: schemas.ProjectDetectLog, auth: Auth = Depends(AllUserAuth())):
    return SuccessResponse(await crud.ProjectDetectLogDal(auth.db).create_data(data=data))


@app.delete("/project/detect/log", summary="删除项目推理记录信息", description="硬删除", tags=["项目推理记录信息"])
async def delete_project_detect_log_list(ids: IdList = Depends(), auth: Auth = Depends(AllUserAuth())):
    await crud.ProjectDetectLogDal(auth.db).delete_datas(ids=ids.ids, v_soft=False)
    return SuccessResponse("删除成功")


@app.put("/project/detect/log/{data_id}", summary="更新项目推理记录信息", tags=["项目推理记录信息"])
async def put_project_detect_log(data_id: int, data: schemas.ProjectDetectLog, auth: Auth = Depends(AllUserAuth())):
    return SuccessResponse(await crud.ProjectDetectLogDal(auth.db).put_data(data_id, data))


@app.get("/project/detect/log/{data_id}", summary="获取项目推理记录信息信息", tags=["项目推理记录信息"])
async def get_project_detect_log(data_id: int, db: AsyncSession = Depends(db_getter)):
    schema = schemas.ProjectDetectLogSimpleOut
    return SuccessResponse(await crud.ProjectDetectLogDal(db).get_data(data_id, v_schema=schema))




###########################################################
#    项目推理记录图片信息
###########################################################
@app.get("/project/detect/log/img", summary="获取项目推理记录图片信息列表", tags=["项目推理记录图片信息"])
async def get_project_detect_log_img_list(p: params.ProjectDetectLogImgParams = Depends(), auth: Auth = Depends(AllUserAuth())):
    datas, count = await crud.ProjectDetectLogImgDal(auth.db).get_datas(**p.dict(), v_return_count=True)
    return SuccessResponse(datas, count=count)


@app.post("/project/detect/log/img", summary="创建项目推理记录图片信息", tags=["项目推理记录图片信息"])
async def create_project_detect_log_img(data: schemas.ProjectDetectLogImg, auth: Auth = Depends(AllUserAuth())):
    return SuccessResponse(await crud.ProjectDetectLogImgDal(auth.db).create_data(data=data))


@app.delete("/project/detect/log/img", summary="删除项目推理记录图片信息", description="硬删除", tags=["项目推理记录图片信息"])
async def delete_project_detect_log_img_list(ids: IdList = Depends(), auth: Auth = Depends(AllUserAuth())):
    await crud.ProjectDetectLogImgDal(auth.db).delete_datas(ids=ids.ids, v_soft=False)
    return SuccessResponse("删除成功")


@app.put("/project/detect/log/img/{data_id}", summary="更新项目推理记录图片信息", tags=["项目推理记录图片信息"])
async def put_project_detect_log_img(data_id: int, data: schemas.ProjectDetectLogImg, auth: Auth = Depends(AllUserAuth())):
    return SuccessResponse(await crud.ProjectDetectLogImgDal(auth.db).put_data(data_id, data))


@app.get("/project/detect/log/img/{data_id}", summary="获取项目推理记录图片信息信息", tags=["项目推理记录图片信息"])
async def get_project_detect_log_img(data_id: int, db: AsyncSession = Depends(db_getter)):
    schema = schemas.ProjectDetectLogImgSimpleOut
    return SuccessResponse(await crud.ProjectDetectLogImgDal(db).get_data(data_id, v_schema=schema))

