#!/usr/bin/python
# -*- coding: utf-8 -*-
# @version        : 1.0
# @Create Time    : 2025/04/03 10:32
# @File           : views.py
# @IDE            : PyCharm
# @desc           : 路由，视图文件

from sqlalchemy.ext.asyncio import AsyncSession
from fastapi import APIRouter, Depends
from . import models, schemas, crud, params
from core.dependencies import IdList
from apps.vadmin.auth.utils.current import AllUserAuth
from utils.response import SuccessResponse
from apps.vadmin.auth.utils.validation.auth import Auth
from core.database import db_getter


app = APIRouter()


###########################################################
#    项目巡逻片信息
###########################################################
@app.get("/project/train", summary="获取项目巡逻片信息列表", tags=["项目巡逻片信息"])
async def get_project_train_list(p: params.ProjectTrainParams = Depends(), auth: Auth = Depends(AllUserAuth())):
    datas, count = await crud.ProjectTrainDal(auth.db).get_datas(**p.dict(), v_return_count=True)
    return SuccessResponse(datas, count=count)


@app.post("/project/train", summary="创建项目巡逻片信息", tags=["项目巡逻片信息"])
async def create_project_train(data: schemas.ProjectTrain, auth: Auth = Depends(AllUserAuth())):
    return SuccessResponse(await crud.ProjectTrainDal(auth.db).create_data(data=data))


@app.delete("/project/train", summary="删除项目巡逻片信息", description="硬删除", tags=["项目巡逻片信息"])
async def delete_project_train_list(ids: IdList = Depends(), auth: Auth = Depends(AllUserAuth())):
    await crud.ProjectTrainDal(auth.db).delete_datas(ids=ids.ids, v_soft=False)
    return SuccessResponse("删除成功")


@app.put("/project/train/{data_id}", summary="更新项目巡逻片信息", tags=["项目巡逻片信息"])
async def put_project_train(data_id: int, data: schemas.ProjectTrain, auth: Auth = Depends(AllUserAuth())):
    return SuccessResponse(await crud.ProjectTrainDal(auth.db).put_data(data_id, data))


@app.get("/project/train/{data_id}", summary="获取项目巡逻片信息信息", tags=["项目巡逻片信息"])
async def get_project_train(data_id: int, db: AsyncSession = Depends(db_getter)):
    schema = schemas.ProjectTrainSimpleOut
    return SuccessResponse(await crud.ProjectTrainDal(db).get_data(data_id, v_schema=schema))

