package com.hxhq.controller;

import com.hxhq.common.ad.JdkADAuthUtil;
import com.hxhq.common.core.web.domain.AjaxResult;
import io.swagger.v3.oas.models.responses.ApiResponse;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author yuyantian
 * @date 2026/2/11
 * @desc
 */
@RestController
@RequestMapping("/ad") // 接口统一前缀
public class ADAuthController {


    // 注入AD工具类（Spring Bean）
    @Resource
    private JdkADAuthUtil jdkADAuthUtil;

    /**
     * 接口1：AD账号密码鉴权
     * 请求示例：POST /ad/validate?username=ELNtest01&password=GLPcd_28
     */
    @PostMapping("/validate")
    public AjaxResult validateAccount(
            @RequestParam String username,
            @RequestParam String password
    ) {
        return jdkADAuthUtil.validateAccount(username, password);
    }

    /**
     * 接口2：验证AD账号是否存在
     * 请求示例：GET /ad/exists?username=ELNtest01
     */
    @GetMapping("/exists")
    public AjaxResult checkAccountExists(@RequestParam String username) {
        return jdkADAuthUtil.checkAccountExists(username);
    }
}
