package cn.iocoder.yudao.module.member.controller.app.userpreference;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.member.controller.app.userpreference.vo.AppUserPreferenceRespVO;
import cn.iocoder.yudao.module.member.controller.app.userpreference.vo.AppUserPreferenceSaveReqVO;
import cn.iocoder.yudao.module.member.dal.dataobject.userpreference.UserPreferenceDO;
import cn.iocoder.yudao.module.member.service.userpreference.UserPreferenceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 APP - 用户偏好")
@RestController
@RequestMapping("/member/user-preference")
@Validated
public class AppUserPreferenceController {

    @Resource
    private UserPreferenceService userPreferenceService;
    //
    //@PostMapping("/create")
    //@Operation(summary = "创建用户偏好")
    //@PreAuthorize("@ss.hasPermission('member:user-preference:create')")
    //public CommonResult<Long> createUserPreference(@Valid @RequestBody UserPreferenceSaveReqVO createReqVO) {
    //    return success(userPreferenceService.createUserPreference(createReqVO));
    //}
    //
    //@PutMapping("/update")
    //@Operation(summary = "更新用户偏好")
    //@PreAuthorize("@ss.hasPermission('member:user-preference:update')")
    //public CommonResult<Boolean> updateUserPreference(@Valid @RequestBody UserPreferenceSaveReqVO updateReqVO) {
    //    userPreferenceService.updateUserPreference(updateReqVO);
    //    return success(true);
    //}
    //
    //@DeleteMapping("/delete")
    //@Operation(summary = "删除用户偏好")
    //@Parameter(name = "id", description = "编号", required = true)
    //@PreAuthorize("@ss.hasPermission('member:user-preference:delete')")
    //public CommonResult<Boolean> deleteUserPreference(@RequestParam("id") Long id) {
    //    userPreferenceService.deleteUserPreference(id);
    //    return success(true);
    //}
    //
    @GetMapping("/get")
    @Operation(summary = "获得用户偏好")
    @Parameter(name = "userId", description = "用户Id", required = true, example = "1024")
    public CommonResult<AppUserPreferenceRespVO> getUserPreference(@RequestParam("userId") Long userId) {
        UserPreferenceDO userPreference = userPreferenceService.getUserPreferenceByUserId(userId);
        return success(BeanUtils.toBean(userPreference, AppUserPreferenceRespVO.class));
    }
    //
    //@GetMapping("/page")
    //@Operation(summary = "获得用户偏好分页")
    //@PreAuthorize("@ss.hasPermission('member:user-preference:query')")
    //public CommonResult<PageResult<UserPreferenceRespVO>> getUserPreferencePage(@Valid UserPreferencePageReqVO pageReqVO) {
    //    PageResult<UserPreferenceDO> pageResult = userPreferenceService.getUserPreferencePage(pageReqVO);
    //    return success(BeanUtils.toBean(pageResult, UserPreferenceRespVO.class));
    //}
    //
    //@GetMapping("/export-excel")
    //@Operation(summary = "导出用户偏好 Excel")
    //@PreAuthorize("@ss.hasPermission('member:user-preference:export')")
    //@OperateLog(type = EXPORT)
    //public void exportUserPreferenceExcel(@Valid UserPreferencePageReqVO pageReqVO,
    //          HttpServletResponse response) throws IOException {
    //    pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
    //    List<UserPreferenceDO> list = userPreferenceService.getUserPreferencePage(pageReqVO).getList();
    //    // 导出 Excel
    //    ExcelUtils.write(response, "用户偏好.xls", "数据", UserPreferenceRespVO.class,
    //                    BeanUtils.toBean(list, UserPreferenceRespVO.class));
    //}
    @PutMapping("/saveOrUpdate")
    @Operation(summary = "设置用户偏好")
    public CommonResult<Boolean> updateUserPreference(@Valid @RequestBody AppUserPreferenceSaveReqVO updateReqVO) {
        return success( userPreferenceService.saveOrUpdate(updateReqVO));
    }



}