package com.backendsys.modules.app.controller;

import com.backendsys.modules.app.entity.AppAuth;
import com.backendsys.modules.app.service.AppAuthService;
import com.backendsys.modules.common.config.security.annotations.Anonymous;
import com.backendsys.modules.common.utils.Result;
import com.backendsys.modules.sdk.wechat.miniprogram.entity.WechatAuth;
import com.backendsys.modules.sdk.wechat.miniprogram.service.WechatAuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Validated
@RestController
@Tag(name = "APP用户登录与注册")
public class AppAuthController {

    @Autowired
    private AppAuthService appAuthService;

    @Autowired
    private WechatAuthService wechatAuthService;

    @Anonymous
    @Operation(summary = "APP登录 (用户名登录)")
    @PostMapping("/api/app/auth/login")
    public Result login(@Validated(AppAuth.Login.class) @RequestBody AppAuth appAuth) {
        return Result.success().put("data", appAuthService.login(appAuth));
    }

    @Anonymous
    @Operation(summary = "微信小程序用户登录")
    @PostMapping("/api/app/auth/loginWithWechatMiniprogram")
    public Result loginWithWechatMiniprogram(@Validated(WechatAuth.Login.class) @RequestBody WechatAuth wechatAuth) {
        return Result.success().put("data", wechatAuthService.loginWithWechatMiniprogram(wechatAuth));
    }

}
