package com.ycwl.basic.controller.mobile;

import com.ycwl.basic.annotation.IgnoreToken;
import com.ycwl.basic.constant.BaseContextHandler;
import com.ycwl.basic.model.mobile.weChat.DTO.WeChatUserInfoDTO;
import com.ycwl.basic.model.mobile.weChat.DTO.WeChatUserInfoUpdateDTO;
import com.ycwl.basic.model.pc.member.resp.MemberRespVO;
import com.ycwl.basic.service.mobile.AppMemberService;
import com.ycwl.basic.utils.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author：longbinbin
 * @Date：2024/12/4 16:54
 */
@RestController
@RequestMapping("/api/mobile/member/v1")
// 用户相关接口
@Slf4j
public class AppMemberController {

    @Autowired
    private AppMemberService memberService;

    /**
     * 登录
     *
     * @param userInfoDTO
     * @return
     * @throws Exception
     */
    // 登录
    @PostMapping("/{scenicId}/login")
    @IgnoreToken
    public ApiResponse<?> login(@PathVariable("scenicId") Long scenicId ,@RequestBody WeChatUserInfoDTO userInfoDTO) throws Exception {
        return memberService.login(scenicId, userInfoDTO.getCode(), userInfoDTO);
    }
    @PostMapping("/undefined/login")
    @IgnoreToken
    public ApiResponse<?> loginUndefined(@RequestBody WeChatUserInfoDTO userInfoDTO) throws Exception {
        return memberService.login(null, userInfoDTO.getCode(), userInfoDTO);
    }
    @PostMapping({"//login", "/login"})
    @IgnoreToken
    public ApiResponse<?> loginNoScenicId(@RequestBody WeChatUserInfoDTO userInfoDTO) throws Exception {
        return memberService.login(null, userInfoDTO.getCode(), userInfoDTO);
    }

    /**
     * 获取用户信息
     *
     * @return
     */
    // 获取用户信息
    @GetMapping("/getUserInfo")
    public ApiResponse<MemberRespVO> getUserInfo() {
        return memberService.getUserInfo();
    }

    /**
     * 修改用户信息
     *
     * @param userInfoUpdateDTO
     * @return
     */
    // 修改用户信息
    @PostMapping("/update")
    public ApiResponse<?> update(@RequestBody WeChatUserInfoUpdateDTO userInfoUpdateDTO) {
        Long userId = Long.parseLong(BaseContextHandler.getUserId());
        return memberService.update(userId, userInfoUpdateDTO);
    }

    // 新增或修改景区服务通知状态
    @GetMapping("/updateScenicServiceNoticeStatus")
    public ApiResponse<String> updateScenicServiceNoticeStatus(Long scenicId) {
        return memberService.updateScenicServiceNoticeStatus(scenicId);
    }

    // 查看景区服务通知状态 0关闭 1开启
    @GetMapping("/getScenicServiceNoticeStatus")
    public ApiResponse<Integer> getScenicServiceNoticeStatus(Long scenicId) {
        return memberService.getScenicServiceNoticeStatus(scenicId);
    }

}