package com.zsElectric.boot.business.controller.applet;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zsElectric.boot.business.model.entity.UserFeedback;
import com.zsElectric.boot.business.model.form.UserFeedbackForm;
import com.zsElectric.boot.business.model.form.applet.AppFeedbackForm;
import com.zsElectric.boot.business.model.query.applet.AppUserOrderInfoQuery;
import com.zsElectric.boot.business.model.vo.applet.AppletUserInfoVO;
import com.zsElectric.boot.business.service.UserFeedbackService;
import com.zsElectric.boot.business.service.UserInfoService;
import com.zsElectric.boot.core.web.Result;
import com.zsElectric.boot.security.util.SecurityUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "用户相关接口")
@RestController
@RequestMapping("/applet/v1/user")
@RequiredArgsConstructor
public class AppletUserController {

    private final UserInfoService userInfoService;

    private final UserFeedbackService userFeedbackService;

    @Operation(summary = "微信小程序获取当前登录信息")
    @GetMapping("/getUserInfo")
    public Result<AppletUserInfoVO> getUserInfo() {
        AppletUserInfoVO userInfoVO = userInfoService.getAppletUserInfo();
        return Result.success(userInfoVO);
    }

    @Operation(summary = "小程序用户反馈")
    @PostMapping("/addUserFeedback")
    public Result<Void> addUserFeedback(@RequestBody @Valid AppFeedbackForm formData ) {
        UserFeedbackForm userFeedbackForm = new UserFeedbackForm();
        userFeedbackForm.setType(formData.getType());
        userFeedbackForm.setDescription(formData.getDescription());
        userFeedbackForm.setImages(formData.getImages());
        userFeedbackForm.setContactWay(formData.getContactWay());
        boolean result = userFeedbackService.saveUserFeedback(userFeedbackForm);
        return Result.judge(result);
    }

    @Operation(summary = "用户反馈答复")
    @GetMapping("/myFeedback")
    public Result<List<UserFeedback>> addUserFeedback() {
        List<UserFeedback> list = userFeedbackService.list(Wrappers.<UserFeedback>lambdaQuery().eq(UserFeedback::getUserId, SecurityUtils.getUserId()));
        return Result.success(list);
    }
}
