package jnpf.cultivate.controller.app.offline;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.cultivate.service.FtbCultivateOfflineTrainService;
import jnpf.model.cultivate.CultivatePage;
import jnpf.model.cultivate.dto.offline.FtbCultivateOfflineTrainDTO;
import jnpf.model.cultivate.dto.offline.FtbCultivateOfflineTrainSignInDTO;
import jnpf.model.cultivate.dto.offline.FtbCultivateOfflineTrainUpdateDTO;
import jnpf.model.cultivate.po.course.FtbCultivateCourse;
import jnpf.model.cultivate.vo.offline.FtbCultivateOfflineTrainDetailsAppVO;
import jnpf.model.cultivate.vo.offline.FtbOfflineTrainingAppPageVO;
import jnpf.util.UserProvider;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * app线下培训模块
 *
 * @author xxxxx
 */
@RestController
@RequestMapping("/app/ftb-cultivate-offline-train")
public class FtbCultivateOfflineTrainAppController {

    @Resource
    private FtbCultivateOfflineTrainService ftbCultivateOfflineTrainService;


    /**
     * 修改培训结果
     *
     * @return {@link ActionResult}
     */
    @PostMapping("/modify-training-results")
    public ActionResult modifyTrainingResults(@RequestBody @Validated FtbCultivateOfflineTrainUpdateDTO offlineTrainUpdateDTO) {
        ftbCultivateOfflineTrainService.updateTrainingResults(UserProvider.getUser(), offlineTrainUpdateDTO);
        return ActionResult.success();
    }

    /**
     * 新增线下培训
     *
     * @return {@link ActionResult}
     */
    @PostMapping("/add")
    public ActionResult add(@RequestBody @Validated FtbCultivateOfflineTrainDTO ftbCultivateOfflineTrainDTO) {
        ftbCultivateOfflineTrainService.add(ftbCultivateOfflineTrainDTO);
        return ActionResult.success();
    }

    /**
     * 线下培训详情
     *
     * @param id 课程主键id
     * @return {@link ActionResult}<{@link FtbCultivateCourse}>
     */
    @GetMapping("/details")
    public ActionResult<FtbCultivateOfflineTrainDetailsAppVO> courseOfflineDetails(String id) {
        FtbCultivateOfflineTrainDetailsAppVO appVO = ftbCultivateOfflineTrainService.offlineAppDetails(id);
        return ActionResult.success(appVO);
    }


    /**
     * 线下培训分页
     *
     * @param cultivatePage 分页模型
     * @param type 查询类型，不传为全部培训，1为我发起的，2为我参与的，3为我负责的
     * @return {@link ActionResult}<{@link Page}<{@link FtbOfflineTrainingAppPageVO}>>
     */
    @GetMapping("/offline-training-pagination")
    public ActionResult<PageListVO<FtbOfflineTrainingAppPageVO>> offlineTrainingApp(CultivatePage cultivatePage, Integer type) {
        Page<FtbOfflineTrainingAppPageVO> page = cultivatePage.coverCultivatePage("a.F_Id");
        page = ftbCultivateOfflineTrainService.offlineTrainingApp(page, type);
        PageListVO<FtbOfflineTrainingAppPageVO> result = CultivatePage.coverPageList(page);
        return ActionResult.success(result);
    }

    /**
     * 线下培训签到
     *
     * @return {@link ActionResult }
     */
    @PostMapping("/signIn")
    public ActionResult signIn(@RequestBody FtbCultivateOfflineTrainSignInDTO freightTrainSignInDTO) {
        ftbCultivateOfflineTrainService.signIn(freightTrainSignInDTO);
        return ActionResult.success();
    }

}
