package shop.alien.store.controller;

import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.store.LifeSys;
import shop.alien.entity.store.UserLoginInfo;
import shop.alien.entity.store.dto.SystemLoginDto;
import shop.alien.entity.store.dto.SystemRegisterDto;
import shop.alien.entity.store.vo.SystemLoginVo;
import shop.alien.store.service.SystemService;
import shop.alien.util.common.TokenInfo;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 商家会员记录 前端控制器
 *
 * @author ssk
 * @since 2025-02-20
 */
@Slf4j
@Api(tags = {"数据中台基础服务接口"})
@ApiSort(1)
@CrossOrigin
@RestController
@RequestMapping("/sys")
@RequiredArgsConstructor
public class SystemController {

    private final SystemService systemService;

    @ApiOperation("web中台登录")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userName", value = "用户名", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "password", value = "密码", dataType = "String", paramType = "query"),
    })
    @PostMapping(value = "/login")
    public R<SystemLoginVo> getStoreVipLogPage(@RequestBody SystemLoginDto systemLogin) {
        return R.data(systemService.login(systemLogin.getUsername(), systemLogin.getPassword()));
    }

    @ApiOperation("web中台退出登录")
    @ApiOperationSupport(order = 2)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userName", value = "用户名", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "password", value = "密码", dataType = "String", paramType = "query"),
    })
    @PostMapping(value = "/logout")
    public R<SystemLoginVo> logout(@ApiIgnore @TokenInfo UserLoginInfo userLoginInfo) {
        return R.success("退出成功");
    }

/**
 * 废弃
  */
//    @ApiOperation("系统用户注册")
//    @ApiOperationSupport(order = 3)
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "userName", value = "用户名", dataType = "String", paramType = "body", required = true),
//            @ApiImplicitParam(name = "password", value = "密码", dataType = "String", paramType = "body", required = true),
//            @ApiImplicitParam(name = "roleId", value = "角色id", dataType = "String", paramType = "body", required = false),
//    })
//    @PostMapping(value = "/register")
//    public R<LifeSys> register(@RequestBody SystemRegisterDto registerDto) {
//        log.info("SystemController.register?userName={},roleId={}", registerDto.getUserName(), registerDto.getRoleId());
//        return systemService.register(registerDto.getUserName(), registerDto.getPassword(), registerDto.getRoleId());
//    }

}
