package org.springblade.modules.member.controller.wx;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.modules.member.entity.MemberEntity;
import org.springblade.modules.member.service.IMemberInfoService;
import org.springframework.web.bind.annotation.*;


/**
 * 控制器
 *
 * @author Chill
 */
@RestController
@AllArgsConstructor
@RequestMapping("/yuecai-wx/member")
@Api(value = "会员信息管理模块", tags = "会员信息管理模块")
public class WXMemberInfoController extends BladeController {

	private final IMemberInfoService memberInfoService;

	/**
	 * 详情
	 */
	@GetMapping("/random/name")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "")
	public R<String> randomName() {
		return R.data(memberInfoService.getRandomName());
	}

	/**
	 * 详情
	 */
	@GetMapping("/random/avatar")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "")
	public R<String> randomAvatar() {
		return R.data(memberInfoService.getRandomAvatar());
	}

	/**
	 * 详情
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "")
	public R<Boolean> saveNicknameAndAvatar(@RequestParam String name, @RequestParam String avatar) {
		Long memberId = AuthUtil.getUserId();
		Boolean status = memberInfoService.update(Wrappers.<MemberEntity>lambdaUpdate()
			.eq(MemberEntity::getId, memberId)
			.set(MemberEntity::getNickName, name)
			.set(MemberEntity::getAvator, avatar));
		return R.data(status);
	}

}
