package cn.hanghui.outapi.platform.tenant.controller;

import cn.hanghui.outapi.platform.common.config.log.Log;
import cn.hanghui.outapi.platform.common.controller.BaseController;
import cn.hanghui.outapi.platform.common.entity.po.Account;
import cn.hanghui.outapi.platform.common.entity.rest.RestResult;
import cn.hanghui.outapi.platform.tenant.entity.config.ampe.AmpeVo;
import cn.hanghui.outapi.platform.tenant.entity.dto.DeviceVo;
import cn.hanghui.outapi.platform.tenant.entity.dto.IotDeviceConfigVo;
import cn.hanghui.outapi.platform.tenant.entity.dto.TenantVo;
import cn.hanghui.outapi.platform.tenant.entity.dto.UserLibDto;
import cn.hanghui.outapi.platform.tenant.entity.dto.ampe.AmpeDeviceDto;
import cn.hanghui.outapi.platform.tenant.entity.dto.ampe.AmpeDeviceSearch;
import cn.hanghui.outapi.platform.tenant.entity.dto.ampe.HhFaceDeviceDto;
import cn.hanghui.outapi.platform.tenant.entity.dto.ampe.HhFaceDeviceSearch;
import cn.hanghui.outapi.platform.tenant.entity.enums.AuthModuleTypeEnum;
import cn.hanghui.outapi.platform.tenant.entity.enums.BusinessTypeEnum;
import cn.hanghui.outapi.platform.tenant.entity.enums.LogTagEnum;
import cn.hanghui.outapi.platform.tenant.service.AmpeService;
import cn.hanghui.outapi.platform.tenant.service.IotDeviceConfigService;
import cn.hanghui.outapi.platform.tenant.service.SceneService;
import cn.hanghui.outapi.platform.tenant.service.TenantService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author shisl
 * @package cn.hanghui.outapi.platform.tenant.controller
 * @class AmpeController
 * @date 2024/7/2 下午1:20
 * @description
 */
@Slf4j
@Api(tags = "授权账号的HHFace设备管理")
@RestController
@RequestMapping(value = "/api/v1/auth/hhface")
public class AuthDeviceController extends BaseController {

    @Autowired
    private TenantService tenantService;

    @Autowired
    private SceneService sceneService;

    @ApiOperation(value = "获取服务商列表")
    @PostMapping("/tenant/list")
    @ApiOperationSupport(order = 1)
    public RestResult<List<TenantVo>> tenantList() {
        return tenantService.getAuthTenantList(getAccount(), AuthModuleTypeEnum.HHFACE_TENANT);
    }

    @ApiOperation(value = "获取用户库列表")
    @PostMapping("/userlib/list")
    @ApiOperationSupport(order = 2)
    public RestResult<List<UserLibDto>> userLibList() {
        return sceneService.getUserLibList(getAccount(), AuthModuleTypeEnum.HHFACE_USER_LIB);
    }

    @ApiOperation(value = "获取HHFace设备列表（分页）")
    @PostMapping("/device/page")
    @ApiOperationSupport(order = 3)
    public RestResult<IPage<DeviceVo>> page(@RequestBody HhFaceDeviceSearch dto) {
        Account account = getAccount();
        return tenantService.page(dto, account);
    }

    @ApiOperation(value = "修改HHFace设备配置信息")
    @PostMapping("/device/update")
    @ApiOperationSupport(order = 4)
    @Log(tag = LogTagEnum.HHFACE,title = "修改HHFace设备配置信息",businessTypeEnum = BusinessTypeEnum.UPDATE)
    public RestResult<Boolean> update(@RequestBody HhFaceDeviceDto dto) {
        Account account = getAccount();
        return tenantService.update(dto, account);
    }


}
