package com.hc.web.controller.browser.back;

import com.hc.business.dto.LiveClassDto;
import com.hc.business.model.LiveClass;
import com.hc.business.service.LiveClassService;
import com.hc.core.utils.result.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * 直播间班级配置表(LiveClass)表控制层
 *
 * @author makejava
 * @since 2024-01-20 11:48:47
 */

@RestController
@RequestMapping("/new/api/back/liveClass")
public class BackLiveClassController {

    /**
     * 服务对象
     */
    private final LiveClassService liveClassService;

    public BackLiveClassController(LiveClassService liveClassService) {
        this.liveClassService = liveClassService;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "依据主键获取 LiveClass", response = Result.class)
    public Result selectDetail(@PathVariable("id") Integer id) {
        return Result.success(this.liveClassService.queryById(id));
    }

    @PostMapping("/insert")
    @ApiOperation(value = "新增 LiveClass", response = Result.class)
    public Result addLiveClass(@Valid @RequestBody LiveClass liveClass) {
        return Result.success(liveClassService.insert(liveClass));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 LiveClass", response = Result.class)
    public Result updateLiveClass(@RequestBody LiveClass liveClass) {
        return Result.success(liveClassService.update(liveClass));
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "依据主键删除 LiveClass", response = Result.class)
    public Result deleteLiveClass(@PathVariable("id") Integer id) {
        return Result.success(liveClassService.deleteById(id));
    }

    @GetMapping("/list")
    @ApiOperation(value = "获取 LiveClass列表(分页)", response = Result.class)
    public Result listLiveClass(@RequestParam(defaultValue = "0") Integer page,
                                @RequestParam(defaultValue = "0") Integer size) {
        return Result.success(liveClassService.queryAllByLimit(page, size));
    }

    @GetMapping("/queryByLiveId")
    @ApiOperation(value = "根据直播间ID，获取下面关联的班级", response = Result.class)
    public Result queryByLiveId(@RequestParam(defaultValue = "0") Integer liveId) {
        List<LiveClassDto> liveClasses = liveClassService.queryByLiveId(liveId);
        return Result.success(liveClasses);
    }
}
