package com.ym.mec.web.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ym.mec.biz.dal.entity.Subject;
import com.ym.mec.biz.dal.entity.SubjectGoodsMapper;
import com.ym.mec.biz.dal.page.SubjectQueryInfo;
import com.ym.mec.biz.service.SubjectService;
import com.ym.mec.common.controller.BaseController;

@RequestMapping("subject")
@Api(tags = "科目服务")
@RestController
public class SubjectController extends BaseController {

    @Autowired
    private SubjectService subjectService;

    @ApiOperation(value = "修改、新增科目")
    @PostMapping("/upset")
    public Object update(@RequestBody Subject subject){
        subjectService.upSetSubject(subject);
        return succeed();
    }

    @ApiOperation(value = "根据科目编号查询科目")
    @GetMapping("/get/{id}")
    public Object get(@ApiParam(value = "科目编号", required = true) @PathVariable("id") Integer id){
        return succeed(subjectService.get(id));
    }

    @ApiOperation(value = "分页查询科目列表")
    @GetMapping("/queryPage")
    public Object queryPage(SubjectQueryInfo queryInfo){
        return succeed(subjectService.queryPage(queryInfo));
    }

    @ApiOperation(value = "分页查询科目树状列表")
    @GetMapping("/queryPageTree")
    public Object queryPageTree(SubjectQueryInfo queryInfo){
        return succeed(subjectService.queryPageTree(queryInfo));
    }

    @ApiOperation(value = "通过乐团编号查询乐团科目规划")
    @GetMapping("/querySubByMusicGroupId")
    @ApiImplicitParams({ @ApiImplicitParam(name = "musicGroupId", value = "乐团编号", required = true, dataType = "Integer")})
    public Object findSubByMusicGroupId(Integer musicGroupId){
        return succeed(subjectService.findSubByMusicGroupId(musicGroupId));
    }

    @ApiOperation(value = "通过乐团收费类型，获取默认的声部列表")
    @GetMapping("/findDefaultSubByGroupId")
    @ApiImplicitParams({ @ApiImplicitParam(name = "musicGroupId", value = "乐团编号", required = true, dataType = "Integer")})
    public Object findDefaultSubByGroupId(Integer musicGroupId){
        return succeed(subjectService.findDefaultSubByGroupId(musicGroupId));
    }

    @ApiOperation(value = "修改、新增声部关联的商品列表")
    @PostMapping("/markGoods")
    public Object markGoods(@RequestBody List<SubjectGoodsMapper> subjectGoodsMappers){
        subjectService.markGoods(subjectGoodsMappers);
        return succeed();
    }

    @ApiOperation(value = "通过乐团编号获取声部列表以及声部报名、缴费、计划人数")
    @GetMapping("/findSubApplyDetail")
    @ApiImplicitParams({ @ApiImplicitParam(name = "musicGroupId", value = "乐团编号", required = true, dataType = "Integer")})
    public Object findSubApplyDetail(Integer musicGroupId){
        return succeed(subjectService.findSubApplyDetail(musicGroupId));
    }
}
