package com.seer.teach.iot.controller.auth;

import com.seer.teach.common.ResultBean;
import com.seer.teach.common.annotation.DecryptionAnnotation;
import com.seer.teach.common.annotation.EncryptionAnnotation;
import com.seer.teach.common.annotation.LogPrint;
import com.seer.teach.iot.common.req.AuthReq;
import com.seer.teach.iot.common.resp.LoginResp;
import com.seer.teach.iot.service.DevicesService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletRequest;

/**
 * 认证控制器
 * 处理设备认证相关的接口请求
 */
@RequestMapping("/device/auth")
@RestController
@Tag(name = "设备认证")
@Validated
/*@EncryptionAnnotation
@DecryptionAnnotation*/
@RequiredArgsConstructor
public class AuthController {

    private final DevicesService devicesService;

    /**
     * 设备登录认证接口
     * 通过验证设备身份信息，生成并返回访问令牌
     *
     * @param params 认证请求参数对象，包含设备身份验证所需的信息
     * @return ResultBean<String> 认证结果封装对象，成功时返回访问令牌
     */
    @LogPrint
    @Operation(summary = "登录")
    @PostMapping("/login")
    public ResultBean<LoginResp> login(@RequestHeader("model") String modelName,
                                       @RequestHeader("versionCode") Integer versionCode,
                                       @RequestBody @Validated AuthReq params,
                                       HttpServletRequest request) {
        LoginResp result = devicesService.login(params, request,modelName,versionCode);
        return ResultBean.success(result);
    }


}
