package com.ruoyi.fadapp.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.fadapp.domain.dto.LoginByCodeDto;
import com.ruoyi.fadapp.domain.dto.SendCodeDto;
import com.ruoyi.fadapp.domain.vo.LoginResultVo;
import com.ruoyi.fadapp.service.IFadAppAuthService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.List;
import com.ruoyi.fadapp.domain.vo.NickDeptVo;

/**
 * FAD APP认证控制器
 *
 * @author ruoyi
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/fadapp/auth")
public class FadAppAuthController {

    private final IFadAppAuthService authService;

    /**
     * 发送验证码
     */
    @PostMapping("/send-code")
    public R<Void> sendCode(@Valid @RequestBody SendCodeDto dto) {
        authService.sendCode(dto.getPhone());
        return R.ok();
    }

    /**
     * 验证码登录
     */
    @PostMapping("/login-by-code")
    public R<LoginResultVo> loginByCode(@Valid @RequestBody LoginByCodeDto dto) {
        LoginResultVo result = authService.loginByCode(dto.getPhone(), dto.getCode());
        return R.ok(result);
    }

    /**
     * 退出登录
     */
    @PostMapping("/logout")
    public R<Void> logout(@RequestHeader("Authorization") String token) {
        authService.logout(token);
        return R.ok();
    }

    /**
     * 根据用户名查部门名称
     */
    @GetMapping("/dept-name")
    public R<String> getDeptNameByUserName(@RequestParam String userName) {
        String deptName = authService.getDeptNameByUserName(userName);
        return R.ok(deptName);
    }
    
    /**
     * 批量根据昵称查询部门名称
     */
    @PostMapping("/dept-names-by-nicks")
    public R<List<NickDeptVo>> getDeptNamesByNickNames(@RequestBody List<String> nickNames) {
        List<NickDeptVo> result = authService.getDeptNamesByNickNames(nickNames);
        return R.ok(result);
    }
} 