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.role_service import RoleService
from module_admin.entity.vo.role_vo import DeleteRoleModel, RoleModel, RolePageQueryModel
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


"""
    当前用不到这个接口
"""


# roleController = APIRouter(prefix='/system/role', dependencies=[Depends(LoginService.get_current_user)])
#
#
# @roleController.get(
#     '/list', response_model=PageResponseModel, dependencies=[Depends(CheckUserInterfaceAuth('system:role:list'))]
# )
# async def get_system_role_list(
#     request: Request,
# role_page_query: RolePageQueryModel = Depends(RolePageQueryModel.as_query),
#     query_db: AsyncSession = Depends(get_db),
# ):
#     # 获取分页数据
#     role_page_query_result = await RoleService.get_role_list_services(query_db, role_page_query, is_page=True)
#     logger.info('获取成功')
#
#     return ResponseUtil.success(model_content=role_page_query_result)


# @roleController.post('', dependencies=[Depends(CheckUserInterfaceAuth('system:role:add'))])
# @ValidateFields(validate_model='add_role')
# @Log(title='系统角色', business_type=BusinessType.INSERT)
# async def add_system_role(
#     request: Request,
#     add_role: RoleModel,
#     query_db: AsyncSession = Depends(get_db),
#     current_user: CurrentUserModel = Depends(LoginService.get_current_user),
# ):
#     add_role.create_time = datetime.now()
#     add_role.create_by = current_user.user.user_name
#     add_role.update_time = datetime.now()
#     add_role.update_by = current_user.user.user_name
#     add_role_result = await RoleService.add_role_services(query_db, add_role)
#     logger.info(add_role_result.message)
#
#     return ResponseUtil.success(msg=add_role_result.message)


# @roleController.put('', dependencies=[Depends(CheckUserInterfaceAuth('system:role:edit'))])
# @ValidateFields(validate_model='edit_role')
# @Log(title='系统角色', business_type=BusinessType.UPDATE)
# async def edit_system_role(
#     request: Request,
#     edit_role: RoleModel,
#     query_db: AsyncSession = Depends(get_db),
#     current_user: CurrentUserModel = Depends(LoginService.get_current_user),
# ):
#     edit_role.update_by = current_user.user.user_name
#     edit_role.update_time = datetime.now()
#     edit_role_result = await RoleService.edit_role_services(query_db, edit_role)
#     logger.info(edit_role_result.message)
#
#     return ResponseUtil.success(msg=edit_role_result.message)


# @roleController.delete('/{robot_role_ids}', dependencies=[Depends(CheckUserInterfaceAuth('system:role:remove'))])
# @Log(title='系统角色', business_type=BusinessType.DELETE)
# async def delete_system_role(request: Request, robot_role_ids: str, query_db: AsyncSession = Depends(get_db)):
#     delete_role = DeleteRoleModel(robotRoleIds=robot_role_ids)
#     delete_role_result = await RoleService.delete_role_services(query_db, delete_role)
#     logger.info(delete_role_result.message)
#
#     return ResponseUtil.success(msg=delete_role_result.message)


# @roleController.get(
#     '/{robot_role_id}', response_model=RoleModel, dependencies=[Depends(CheckUserInterfaceAuth('system:role:query'))]
# )
# async def query_detail_system_role(request: Request, robot_role_id: int, query_db: AsyncSession = Depends(get_db)):
#     role_detail_result = await RoleService.role_detail_services(query_db, robot_role_id)
#     logger.info(f'获取robot_role_id为{robot_role_id}的信息成功')
#
#     return ResponseUtil.success(data=role_detail_result)


# @roleController.post('/export', dependencies=[Depends(CheckUserInterfaceAuth('system:role:export'))])
# @Log(title='系统角色', business_type=BusinessType.EXPORT)
# async def export_system_role_list(
#     request: Request,
#     role_page_query: RolePageQueryModel = Form(),
#     query_db: AsyncSession = Depends(get_db),
# ):
#     # 获取全量数据
#     role_query_result = await RoleService.get_role_list_services(query_db, role_page_query, is_page=False)
#     role_export_result = await RoleService.export_role_list_services(role_query_result)
#     logger.info('导出成功')
#
#     return ResponseUtil.streaming(data=bytes2file_response(role_export_result))
