package com.fuyuanshen.app.controller;

import com.fuyuanshen.app.model.AppRegisterBody;
import com.fuyuanshen.app.model.AppUpdatePasswordBody;
import com.fuyuanshen.app.service.AppLoginService;
import com.fuyuanshen.app.service.AppRegisterService;
import com.fuyuanshen.common.core.domain.R;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * APP我的
 *
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/userCenter")
public class AppUserCenterController {

    private final AppLoginService loginService;
    private final AppRegisterService registerService;
    /**
     * 用户注销
     */
    @PostMapping("/cancelAccount")
    public R<Void> cancelAccount() {
        loginService.cancelAccount();
        return R.ok("用户注销成功");
    }


    /**
     * 修改密码
     */
    @PostMapping("/updatePassword")
    public R<Void> updatePassword(@Validated @RequestBody AppUpdatePasswordBody body) {
        registerService.updatePassword(body);
        return R.ok();
    }

    /**
     * 退出登录
     */
    @PostMapping("/logout")
    public R<Void> logout() {
        loginService.logout();
        return R.ok("退出成功");
    }
}
