package com.ruoyi.web.modules.technology.controller;

import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.web.modules.technology.domain.PracticalTrainingMyEnrollListVo;
import com.ruoyi.web.modules.technology.service.IBizPracticalTrainingAppService;

/**
 * 移动端实战业务培训（我的报名、报名、取消报名）。
 */
@RestController
@RequestMapping("/app/practicalTraining")
public class BizAppPracticalTrainingController extends BaseController
{
    @Autowired
    private IBizPracticalTrainingAppService bizPracticalTrainingAppService;

    @GetMapping("/myEnroll/list")
    public TableDataInfo myEnrollList()
    {
        startPage();
        List<PracticalTrainingMyEnrollListVo> list =
                bizPracticalTrainingAppService.selectMyEnrollList(SecurityUtils.getUserId());
        return getDataTable(list);
    }

    @GetMapping("/myEnroll/{id}")
    public AjaxResult myEnrollDetail(@PathVariable("id") Long id)
    {
        return success(bizPracticalTrainingAppService.selectMyEnrollDetail(id, SecurityUtils.getUserId()));
    }

    @Log(title = "移动端实战培训报名", businessType = BusinessType.INSERT)
    @PostMapping("/{id}/enroll")
    public AjaxResult enroll(@PathVariable("id") Long id)
    {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        String name = user.getNickName() != null ? user.getNickName() : user.getUserName();
        return toAjax(bizPracticalTrainingAppService.enroll(id, user.getUserId(), name, getUsername()));
    }

    @Log(title = "移动端实战培训取消报名", businessType = BusinessType.UPDATE)
    @PostMapping("/{id}/cancelEnroll")
    public AjaxResult cancelEnroll(@PathVariable("id") Long id)
    {
        return toAjax(bizPracticalTrainingAppService.cancelEnroll(id, SecurityUtils.getUserId(), getUsername()));
    }
}
