package com.yingpaipay.web.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.stp.StpUtil;
import com.yingpaipay.web.domain.bo.AppletLoginBo;
import com.yingpaipay.web.domain.vo.AppletLoginVo;
import com.yingpaipay.web.service.factory.AppletAuthStrategyFactory;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
import org.dromara.common.web.core.BaseController;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: Huanyi
 * @CreateTime: 2025-11-26
 * @Description:
 * @Version: 1.0
 */

@SaIgnore
@RestController
@RequiredArgsConstructor
@RequestMapping("/applet/auth")
@Slf4j
public class AppletAuthController extends BaseController {

    private final AppletAuthStrategyFactory factory;

    @PostMapping("/login/{strategy}")
    public R<AppletLoginVo> login(@PathVariable("strategy") String strategy, @RequestBody AppletLoginBo bo) {
        return R.ok(factory.getInstance(strategy).login(bo));
    }

    @DeleteMapping("/logout")
    public R<Void> logout() {
        Object loginId = StpUtil.getLoginId();
        StpUtil.logout();
        log.warn("退出登录,ID: {}", loginId);
        return R.ok();
    }

}
