package com.ym.mec.student.controller;

import com.ym.mec.biz.dal.dto.QueryConditionDto;
import com.ym.mec.biz.dal.page.StudentDemoGroupQueryInfo;
import com.ym.mec.biz.service.DemoGroupService;
import com.ym.mec.biz.service.SubjectService;
import com.ym.mec.common.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @Author Joburgess
 * @Date 2019/9/25
 */
@Api(tags = "试听课-学生端")
@RequestMapping("studentDemoGroup")
@RestController
public class StudentDemoGroupController extends BaseController {

    @Autowired
    private DemoGroupService demoGroupService;
    @Autowired
    private SubjectService subjectService;

    @ApiOperation("获取试听课筛选条件")
    @GetMapping(value = "/findQueryCondition")
    public Object findQueryCondition(){
        List<QueryConditionDto> conditions=new ArrayList<>();
        conditions.add(new QueryConditionDto("乐器选择","subjectId",subjectService.findSubjectConditions()));
        return succeed(conditions);
    }

    @ApiOperation(value = "试听课列表获取")
    @PostMapping("/queryStudentDemoGroups")
    public Object queryStudentDemoGroups(@RequestBody StudentDemoGroupQueryInfo queryInfo){
        if(Objects.isNull(queryInfo.getSubjectIds())||Objects.isNull(queryInfo.getStartTime())){
            return failed("参数错误!");
        }
        return succeed(demoGroupService.queryStudentDemoGroups(queryInfo));
    }

    @ApiOperation(value = "试听课订阅")
    @PostMapping("/demoGroupSubscribe")
    public Object demoGroupSubscribe(Long demoGroupId,Long coursePlanId){
        demoGroupService.demoGroupSubscribe(demoGroupId,coursePlanId);
        return succeed();
    }
}
