package com.ym.mec.student.controller;

import com.ym.mec.biz.dal.dto.ConditionDto;
import com.ym.mec.biz.dal.dto.QueryConditionDto;
import com.ym.mec.biz.dal.dto.VipGroupBuyParamsDto;
import com.ym.mec.biz.dal.page.StudentVipGroupQueryInfo;
import com.ym.mec.biz.service.SubjectService;
import com.ym.mec.biz.service.VipGroupService;
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.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author Joburgess
 * @Date 2019/9/23
 */

@Api(tags = "vip课-学生端")
@RequestMapping("studentVipGroup")
@RestController
public class StudentVipGroupController extends BaseController {

    @Autowired
    private VipGroupService vipGroupService;
    @Autowired
    private SubjectService subjectService;

    @ApiOperation(value = "获取vip课列表筛选条件")
    @GetMapping(value = "/findQueryCondition")
    public Object findQueryCondition(){
        List<QueryConditionDto> conditions=new ArrayList<>();
        conditions.add(new QueryConditionDto("乐器选择","subjectId",subjectService.findSubjectConditions()));
        List<ConditionDto> conditionDtos=new ArrayList<>();
        conditionDtos.add(new ConditionDto(0L,"线下"));
        conditionDtos.add(new ConditionDto(1L,"线上"));
        conditions.add(new QueryConditionDto("类别选择","classType",conditionDtos));
        return succeed(conditions);
    }

    @ApiOperation(value = "获取vip课列表")
    @PostMapping(value = "/queryVipGroups")
    public Object queryVipGroups(@RequestBody StudentVipGroupQueryInfo queryInfo){
        Map<String,Object> result=new HashMap<>();
        result.put("recommendVipGroups",new ArrayList<>());
        result.put("pageInfo",vipGroupService.findStudentVipGroupList(queryInfo));
        return succeed(result);
    }

    @ApiOperation(value = "获取学生端vip课显示详情")
    @GetMapping(value = "/getVipGroupShowDetail")
    public Object getVipGroupShowDetail(Long vipGroupId){
        return succeed(vipGroupService.getVipGroupShowDetail(vipGroupId));
    }

    @ApiOperation(value = "vip课购买")
    @PostMapping("/buyVipGroup")
    public Object buyVipGroup(VipGroupBuyParamsDto vipGroupBuyParams) throws Exception {
        return succeed(vipGroupService.buyVipGroup(vipGroupBuyParams));
    }

    @ApiOperation(value = "vip课退课")
    @PostMapping("/applyRefund")
    public Object applyRefund(Long vipGroupId){
        vipGroupService.applyRefund(vipGroupId,null);
        return succeed();
    }

}
