package com.zhongzheng.controller.activity;

import com.zhongzheng.common.core.controller.BaseController;
import com.zhongzheng.common.core.domain.AjaxResult;
import com.zhongzheng.common.core.page.TableDataInfo;
import com.zhongzheng.common.utils.ServletUtils;
import com.zhongzheng.controller.wx.WxLoginController;
import com.zhongzheng.framework.web.service.WxTokenService;
import com.zhongzheng.modules.activity.bo.ActivityTaskQueryBo;
import com.zhongzheng.modules.activity.bo.ActivityTaskUserAddBo;
import com.zhongzheng.modules.activity.service.IActivityTaskService;
import com.zhongzheng.modules.activity.vo.ActivityTaskVo;
import com.zhongzheng.modules.user.bo.UserPlanAddBo;
import com.zhongzheng.modules.user.bo.UserPlanQueryBo;
import com.zhongzheng.modules.user.domain.UserPlan;
import com.zhongzheng.modules.user.entity.ClientLoginUser;
import com.zhongzheng.modules.user.service.IUserPlanService;
import com.zhongzheng.modules.user.vo.CalendarStudyVo;
import com.zhongzheng.modules.user.vo.UserPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 任务存储Controller
 *
 * @author change
 * @date 2021-05-19
 */
@Api(value = "计划生成", tags = {"计划生成"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/plan")
public class PlanController extends BaseController {

    private final IUserPlanService userPlanService;

    private final WxTokenService WxTokenService;

    /**
     * 查询任务積分列表
     */
    @ApiOperation("生成学习计划")
    @GetMapping("/generate")
    public AjaxResult<UserPlanVo> list(UserPlanQueryBo bo) throws ParseException {
        ClientLoginUser loginUser = WxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        return AjaxResult.success(userPlanService.generate(bo));
    }

    /**
     * 获得用户学习计划
     */
    @ApiOperation("获得用户学习计划")
    @GetMapping("/userPlan")
    public AjaxResult<List<UserPlanVo>> userPlan(UserPlanQueryBo bo) throws ParseException {
        ClientLoginUser loginUser = WxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        return AjaxResult.success(userPlanService.userPlan(bo));
    }


    /**
     * 获得七天活动计划
     */
    @ApiOperation("获得七天活动计划")
    @GetMapping("/userPlanSeven")
    public AjaxResult<UserPlanVo> userPlanSeven(UserPlanQueryBo bo) throws ParseException {
        ClientLoginUser loginUser = WxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        return AjaxResult.success(userPlanService.userPlanSeven(bo));
    }


    /**
     * 修改任务
     */
    @ApiOperation("修改计划")
    @PostMapping("/updateGenerate")
    public AjaxResult<Void> updateGenerate(@RequestBody UserPlanAddBo bo) throws ParseException {
        ClientLoginUser loginUser = WxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        return toAjax(userPlanService.updateGenerate(bo) ? 1 : 0);
    }


    /**
     * 获得用户学习计划
     */
    @ApiOperation("用户未完成任务重新更新任务")
    @PostMapping("/editPlan")
    public AjaxResult<Void> editPlan(@RequestBody UserPlanQueryBo bo) throws ParseException {
        ClientLoginUser loginUser = WxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        return toAjax(userPlanService.editPlan(bo) ? 1 : 0);
    }
}
