package com.pangu.web.controller.system;

import com.pangu.common.core.domain.AjaxResult;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 登录控制器
 * 
 * @author 湖北新华业务中台研发团队
 */
@RestController
public class SysLoginController {

    /**
     * 获取用户信息
     */
    @GetMapping("/api/getInfo")
    public AjaxResult getInfo() {
        Map<String, Object> data = new HashMap<>();
        Map<String, Object> user = new HashMap<>();
        user.put("userId", 1L);
        user.put("userName", "admin");
        user.put("nickName", "管理员");
        user.put("roles", new String[]{"admin"});
        user.put("permissions", new String[]{"*:*:*"});
        
        data.put("user", user);
        data.put("roles", new String[]{"admin"});
        data.put("permissions", new String[]{"*:*:*"});
        
        return AjaxResult.success(data);
    }

    /**
     * 用户登录
     */
    @PostMapping("/api/login")
    public AjaxResult login(@RequestBody Map<String, String> loginBody) {
        Map<String, Object> data = new HashMap<>();
        data.put("token", "mock-token-" + System.currentTimeMillis());
        return AjaxResult.success(data);
    }

    /**
     * 用户退出
     */
    @PostMapping("/api/logout")
    public AjaxResult logout() {
        return AjaxResult.success("退出成功");
    }

    /**
     * 获取验证码
     */
    @GetMapping("/api/captchaImage")
    public AjaxResult getCaptchaImage() {
        Map<String, Object> data = new HashMap<>();
        data.put("uuid", "mock-uuid-" + System.currentTimeMillis());
        data.put("img", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==");
        data.put("captchaEnabled", false);
        return AjaxResult.success(data);
    }
}
