package com.greenorange.promotion.controller.course;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.greenorange.promotion.annotation.RequiresPermission;
import com.greenorange.promotion.annotation.SysLog;
import com.greenorange.promotion.common.BaseResponse;
import com.greenorange.promotion.common.ErrorCode;
import com.greenorange.promotion.common.ResultUtils;
import com.greenorange.promotion.constant.UserConstant;
import com.greenorange.promotion.exception.BusinessException;
import com.greenorange.promotion.exception.ThrowUtils;
import com.greenorange.promotion.model.dto.CommonBatchRequest;
import com.greenorange.promotion.model.dto.coursePromotionCommissionPending.CoursePromotionCommissionPendingAddRequest;
import com.greenorange.promotion.model.dto.coursePromotionCommissionPending.CoursePromotionCommissionPendingQueryRequest;
import com.greenorange.promotion.model.dto.coursePromotionCommissionPending.CoursePromotionCommissionPendingUpdateRequest;
import com.greenorange.promotion.model.entity.CoursePromotionCommissionPending;
import com.greenorange.promotion.model.entity.UserInfo;
import com.greenorange.promotion.model.entity.UserPerformanceSummary;
import com.greenorange.promotion.model.enums.CommissionStatusEnum;
import com.greenorange.promotion.model.enums.UserRoleEnum;
import com.greenorange.promotion.model.vo.coursePromotionCommissionPending.CoursePromotionCommissionPendingVO;
import com.greenorange.promotion.service.common.CommonService;
import com.greenorange.promotion.service.course.CoursePromotionCommissionPendingService;
import com.greenorange.promotion.service.userInfo.UserInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.greenorange.promotion.model.dto.CommonRequest;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.swing.*;
import java.math.BigDecimal;
import java.util.List;


///**
// * 课程推广待提成记录 控制器
// */
//@RestController
//@RequestMapping("coursePromo")
//@Slf4j
//@Tag(name = "课程推广待提成记录模块")
//@Transactional
//public class CoursePromotionCommissionPendingController {
//
//    @Resource
//    private CoursePromotionCommissionPendingService coursePromotionCommissionPendingService;
//
//    @Resource
//    private CommonService commonService;
//
//    @Resource
//    private UserInfoService userInfoService;
//



//
//    /**
//     * 小程序端根据（一级）（二级）用户id查询课程推广待提成记录
//     * @return 是否修改成功
//     */
//    @PostMapping("query/userId")
//    @Operation(summary = "小程序端根据（一级）（二级）用户id查询课程推广待提成记录", description = "参数：无，权限：管理员，方法名：queryCoursePromotionCommissionPendingByUserId")
//    @RequiresPermission(mustRole = UserConstant.DEFAULT_ROLE)
//    @SysLog(title = "课程推广待提成记录管理", content = "小程序端根据（一级）（二级）用户id查询课程推广待提成记录")
//    public BaseResponse<List<CoursePromotionCommissionPendingVO>> queryCoursePromotionCommissionPendingByUserId(HttpServletRequest request) {
//        Long userId = (Long) request.getAttribute("userId");
//        UserInfo userInfo = userInfoService.getById(userId);
//        String userRole = userInfo.getUserRole();
//        UserRoleEnum userRoleEnum = UserRoleEnum.getEnumByValue(userRole);
//        LambdaQueryWrapper<CoursePromotionCommissionPending> lambdaQueryWrapper = new LambdaQueryWrapper<>();
//        if (UserRoleEnum.SUPERVISOR.equals(userRoleEnum)) {
//            lambdaQueryWrapper.eq(CoursePromotionCommissionPending::getFirstUserId, userId);
//        }else if (UserRoleEnum.STAFF.equals(userRoleEnum)) {
//            lambdaQueryWrapper.eq(CoursePromotionCommissionPending::getSecondUserId, userId);
//        } else {
//            throw new BusinessException(ErrorCode.NO_AUTH_ERROR);
//        }
//        List<CoursePromotionCommissionPending> coursePromotionCommissionPendingList = coursePromotionCommissionPendingService.list(lambdaQueryWrapper);
//        List<CoursePromotionCommissionPendingVO> coursePromotionCommissionPendingVOS = commonService.convertList(coursePromotionCommissionPendingList, CoursePromotionCommissionPendingVO.class);
//        return ResultUtils.success(coursePromotionCommissionPendingVOS);
//    }
//
//
//
//
//
//
//
//    /**
//     * web端管理员根据id查询课程推广待提成记录
//     * @param commonRequest 课程推广待提成记录id
//     * @return 是否修改成功
//     */
//    @PostMapping("query/id")
//    @Operation(summary = "web端管理员根据id查询课程推广待提成记录", description = "参数：课程推广待提成记录id，权限：管理员，方法名：queryCoursePromotionCommissionPendingById")
//    @RequiresPermission(mustRole = UserConstant.DEFAULT_ROLE)
//    @SysLog(title = "课程推广待提成记录管理", content = "web端管理员根据id查询课程推广待提成记录")
//    public BaseResponse<CoursePromotionCommissionPendingVO> queryCoursePromotionCommissionPendingById(@Valid @RequestBody CommonRequest commonRequest) {
//        Long id = commonRequest.getId();
//        CoursePromotionCommissionPending coursePromotionCommissionPending = coursePromotionCommissionPendingService.getById(id);
//        CoursePromotionCommissionPendingVO coursePromotionCommissionPendingVO = commonService.copyProperties(coursePromotionCommissionPending, CoursePromotionCommissionPendingVO.class);
//        return ResultUtils.success(coursePromotionCommissionPendingVO);
//    }
//
//
//    /**
//     * web端管理员根据id修改课程推广待提成记录状态
//     * @param commonRequest 课程推广待提成记录id
//     * @return 是否修改成功
//     */
//    @PostMapping("update")
//    @Operation(summary = "web端管理员根据id修改课程推广待提成记录状态", description = "参数：课程推广待提成记录id，权限：管理员，方法名：modifyCoursePromotionCommissionPendingStatus")
//    @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
//    @SysLog(title = "课程推广待提成记录管理", content = "web端管理员根据id修改课程推广待提成记录状态")
//    public BaseResponse<Boolean> modifyCoursePromotionCommissionPendingStatus(@Valid @RequestBody CommonRequest commonRequest) {
//        Long id = commonRequest.getId();
//        CoursePromotionCommissionPending coursePromotionCommissionPending = coursePromotionCommissionPendingService.getById(id);
//        String commissionStatus = coursePromotionCommissionPending.getCommissionStatus();
//        ThrowUtils.throwIf(!commissionStatus.equals(CommissionStatusEnum.PENDING.getValue()), ErrorCode.OPERATION_ERROR, "课程推广待提成记录状态错误");
//        LambdaUpdateWrapper<CoursePromotionCommissionPending> updateWrapper = new LambdaUpdateWrapper<>();
//        updateWrapper.eq(CoursePromotionCommissionPending::getId, id).set(CoursePromotionCommissionPending::getCommissionStatus, CommissionStatusEnum.COMPLETED.getValue());
//        coursePromotionCommissionPendingService.update(updateWrapper);
//        return ResultUtils.success(true);
//    }
//
//
//    /**
//     * Web端管理员分页查询课程推广待提成记录
//     * @param coursePromotionCommissionPendingQueryRequest 课程推广待提成记录查询请求体
//     * @return 课程推广待提成记录列表
//     */
//    @PostMapping("page")
//    @Operation(summary = "Web端管理员分页查询课程推广待提成记录", description = "参数：课程推广待提成记录查询请求体，权限：管理员，方法名：listCoursePromotionCommissionPendingByPage")
//    @RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
//    @SysLog(title = "课程推广待提成记录管理", content = "Web端管理员分页查询课程推广待提成记录")
//    public BaseResponse<Page<CoursePromotionCommissionPendingVO>> listCoursePromotionCommissionPendingByPage(@Valid @RequestBody CoursePromotionCommissionPendingQueryRequest coursePromotionCommissionPendingQueryRequest) {
//        long current = coursePromotionCommissionPendingQueryRequest.getCurrent();
//        long pageSize = coursePromotionCommissionPendingQueryRequest.getPageSize();
//        QueryWrapper<CoursePromotionCommissionPending> queryWrapper = coursePromotionCommissionPendingService.getQueryWrapper(coursePromotionCommissionPendingQueryRequest);
//        Page<CoursePromotionCommissionPending> page = coursePromotionCommissionPendingService.page(new Page<>(current, pageSize), queryWrapper);
//        List<CoursePromotionCommissionPending> coursePromotionCommissionPendingList = page.getRecords();
//        List<CoursePromotionCommissionPendingVO> coursePromotionCommissionPendingVOList = commonService.convertList(coursePromotionCommissionPendingList, CoursePromotionCommissionPendingVO.class);
//        Page<CoursePromotionCommissionPendingVO> voPage = new Page<>(current, pageSize);
//        voPage.setRecords(coursePromotionCommissionPendingVOList);
//        voPage.setPages(page.getPages());
//        voPage.setTotal(page.getTotal());
//        return ResultUtils.success(voPage);
//    }
//}