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.service.login_service import LoginService
from module_admin.service.haikang_service import HaiKangService
from utils.log_util import logger
from utils.page_util import PageResponseModel
from utils.response_util import ResponseUtil
from module_admin.entity.vo.haikang_vo import VisitorReservationQueryModel

from typing import List


haikang_controller = APIRouter(prefix="/system/haikang", dependencies=[Depends(LoginService.get_current_user)])


# # 查询门禁点列表
# @haikang_controller.get("/door_list"
#                         # , response_model=PageResponseModel
#                         # , dependencies=[Depends(CheckUserInterfaceAuth("system:haikang:list"))]
#                         )
# async def get_system_haikang_list(
#     request: Request,
#     pageNo:int,
#     pageSize:int,
# ):
#     """
#     查询门禁点列表
#     """
#     result = await HaiKangService.get_door_list_service(pageNo, pageSize)
#     return parse_result(result)
    
# # 查询门禁点状态
# @haikang_controller.post(
#     "/door_status",
#     # dependencies=[Depends(CheckUserInterfaceAuth("system:haikang:list"))]
# )
# async def get_door_status(
#     request: Request,
#     door_index_codes: List[str],
# ):
#     """
#     查询门禁点列表
#     """
#     result = await HaiKangService.get_door_status_service(door_index_codes)
#     return parse_result(result)

# # 门禁点反控
# @haikang_controller.post(
#     "/door_do_control",
#     # dependencies=[Depends(CheckUserInterfaceAuth("system:haikang:list"))]
# )
# async def door_do_control(
#     request: Request,
#     door_index_codes: List[str],
#     control_type: int,
# ):
#     pass

# 查询访客预约记录
@haikang_controller.post(
    "/get_visitor_list",
    # dependencies=[Depends(CheckUserInterfaceAuth("system:haikang:list"))]
)
async def get_visitor(
    request: Request,
    visitor_query: VisitorReservationQueryModel
):
    result = await HaiKangService.get_visitor_list_service(visitor_query)
    return parse_result(result)

    
def parse_result(result):
    if result[0]:
        return ResponseUtil.success(data=result[1])
    return ResponseUtil.error(msg=f"code:{result[1]} msg:{result[2]}")