from datetime import datetime
from fastapi import APIRouter, Depends, Form, Request
from pydantic_validation_decorator import ValidateFields
from sqlalchemy.ext.asyncio import AsyncSession
from config.enums import BusinessType
from config.get_db import get_db
from module_admin.annotation.log_annotation import Log
from module_admin.aspect.interface_auth import CheckUserInterfaceAuth
from module_admin.entity.vo.user_vo import CurrentUserModel
from module_admin.service.login_service import LoginService
from module_admin.service.sys_alert_service import Sys_alertService
from module_admin.entity.vo.sys_alert_vo import DeleteSys_alertModel, Sys_alertModel, Sys_alertPageQueryModel
from utils.common_util import bytes2file_response
from utils.log_util import logger
from utils.page_util import PageResponseModel
from utils.response_util import ResponseUtil


sys_alertController = APIRouter(prefix='/system/sys_alert', dependencies=[Depends(LoginService.get_current_user)])


# @sys_alertController.get(
#     '/list', response_model=PageResponseModel
#     # , dependencies=[Depends(CheckUserInterfaceAuth('system:sys_alert:list'))]
# )
# async def get_system_sys_alert_list(
#     request: Request,
#     sys_alert_page_query: Sys_alertPageQueryModel = Depends(Sys_alertPageQueryModel.as_query),
#     query_db: AsyncSession = Depends(get_db),
# ):
#     # 获取分页数据
#     sys_alert_page_query_result = await Sys_alertService.get_sys_alert_list_services(query_db, sys_alert_page_query, is_page=True)
#     logger.info('获取成功')

#     return ResponseUtil.success(model_content=sys_alert_page_query_result)


# @sys_alertController.post('', dependencies=[Depends(CheckUserInterfaceAuth('system:sys_alert:add'))])
# @ValidateFields(validate_model='add_sys_alert')
# @Log(title='系统告警', business_type=BusinessType.INSERT)
# async def add_system_sys_alert(
#     request: Request,
#     add_sys_alert: Sys_alertModel,
#     query_db: AsyncSession = Depends(get_db),
#     current_user: CurrentUserModel = Depends(LoginService.get_current_user),
# ):
#     add_sys_alert.create_time = datetime.now()
#     add_sys_alert.create_by = current_user.user.user_name
#     add_sys_alert.update_time = datetime.now()
#     add_sys_alert.update_by = current_user.user.user_name
#     add_sys_alert_result = await Sys_alertService.add_sys_alert_services(query_db, add_sys_alert)
#     logger.info(add_sys_alert_result.message)

#     return ResponseUtil.success(msg=add_sys_alert_result.message)


# @sys_alertController.put('', dependencies=[Depends(CheckUserInterfaceAuth('system:sys_alert:edit'))])
# @ValidateFields(validate_model='edit_sys_alert')
# @Log(title='系统告警', business_type=BusinessType.UPDATE)
# async def edit_system_sys_alert(
#     request: Request,
#     edit_sys_alert: Sys_alertModel,
#     query_db: AsyncSession = Depends(get_db),
#     current_user: CurrentUserModel = Depends(LoginService.get_current_user),
# ):
#     edit_sys_alert.update_by = current_user.user.user_name
#     edit_sys_alert.update_time = datetime.now()
#     edit_sys_alert_result = await Sys_alertService.edit_sys_alert_services(query_db, edit_sys_alert)
#     logger.info(edit_sys_alert_result.message)

#     return ResponseUtil.success(msg=edit_sys_alert_result.message)


# @sys_alertController.delete('/{ids}', dependencies=[Depends(CheckUserInterfaceAuth('system:sys_alert:remove'))])
# @Log(title='系统告警', business_type=BusinessType.DELETE)
# async def delete_system_sys_alert(request: Request, ids: str, query_db: AsyncSession = Depends(get_db)):
#     delete_sys_alert = DeleteSys_alertModel(ids=ids)
#     delete_sys_alert_result = await Sys_alertService.delete_sys_alert_services(query_db, delete_sys_alert)
#     logger.info(delete_sys_alert_result.message)

#     return ResponseUtil.success(msg=delete_sys_alert_result.message)


# @sys_alertController.get(
#     '/{id}', response_model=Sys_alertModel, dependencies=[Depends(CheckUserInterfaceAuth('system:sys_alert:query'))]
# )
# async def query_detail_system_sys_alert(request: Request, id: int, query_db: AsyncSession = Depends(get_db)):
#     sys_alert_detail_result = await Sys_alertService.sys_alert_detail_services(query_db, id)
#     logger.info(f'获取id为{id}的信息成功')

#     return ResponseUtil.success(data=sys_alert_detail_result)


# @sys_alertController.post('/export', dependencies=[Depends(CheckUserInterfaceAuth('system:sys_alert:export'))])
# @Log(title='系统告警', business_type=BusinessType.EXPORT)
# async def export_system_sys_alert_list(
#     request: Request,
#     sys_alert_page_query: Sys_alertPageQueryModel = Form(),
#     query_db: AsyncSession = Depends(get_db),
# ):
#     # 获取全量数据
#     sys_alert_query_result = await Sys_alertService.get_sys_alert_list_services(query_db, sys_alert_page_query, is_page=False)
#     sys_alert_export_result = await Sys_alertService.export_sys_alert_list_services(sys_alert_query_result)
#     logger.info('导出成功')

#     return ResponseUtil.streaming(data=bytes2file_response(sys_alert_export_result))
