package com.xinelu.manage.controller.trainingorder;

import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.manage.domain.trainingorder.TrainingOrder;
import com.xinelu.manage.domain.trainingorderitemdirectory.TrainingOrderItemDirectory;
import com.xinelu.manage.service.trainingorder.ITrainingOrderService;
import com.xinelu.manage.vo.trainingorder.TrainingOrderVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 学习培训订单Controller
 *
 * @author xinyilu
 * @date 2023-04-20
 */
@RestController
@RequestMapping("/system/trainingOrder")
public class TrainingOrderController extends BaseController {
    @Resource
    private ITrainingOrderService trainingOrderService;

    /**
     * 查询学习培训订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:trainingOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(TrainingOrderVO trainingOrder) {
        startPage();
        List<TrainingOrderVO> list = trainingOrderService.selectTrainingOrderList(trainingOrder);
        return getDataTable(list);
    }

    /**
     * 获取学习培训订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:trainingOrder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(trainingOrderService.selectTrainingOrderById(id));
    }

    /**
     * 新增学习培训订单
     */
    @PreAuthorize("@ss.hasPermi('system:trainingOrder:add')")
    @Log(title = "学习培训订单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody TrainingOrder trainingOrder) {
        return toAjax(trainingOrderService.insertTrainingOrder(trainingOrder));
    }

    /**
     * 修改学习培训订单
     */
    @PreAuthorize("@ss.hasPermi('system:trainingOrder:edit')")
    @Log(title = "学习培训订单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody TrainingOrder trainingOrder) {
        return toAjax(trainingOrderService.updateTrainingOrder(trainingOrder));
    }

    /**
     * 删除学习培训订单
     */
    @PreAuthorize("@ss.hasPermi('system:trainingOrder:remove')")
    @Log(title = "学习培训订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(trainingOrderService.deleteTrainingOrderByIds(ids));
    }

    /**
     * 退款信息查询
     */
    @GetMapping("/refundInformation")
    public AjaxResult selectRefundInformation(Long id) {
        if (Objects.isNull(id)) {
            return AjaxResult.error("请选择需要退款的信息！");
        }
        return trainingOrderService.selectRefundInformation(id);
    }

    /**
     * 查询学习培训订单明细章节，记录视频学习和直播课程的章节信息列表
     */
    @GetMapping("/orderItemDirectory")
    public TableDataInfo selectTrainingOrderItemDirectoryList(TrainingOrderItemDirectory trainingOrderItemDirectory) {
        startPage();
        List<TrainingOrderItemDirectory> list = trainingOrderService.selectTrainingOrderItemDirectoryList(trainingOrderItemDirectory);
        return getDataTable(list);
    }
}