package com.sv.api.controller;

import com.sv.dto.api.VenueLessonDTO;
import com.sv.entity.VenueLesson;
import com.sv.service.api.MemberCardService;
import com.sv.service.api.VenueLessonService;
import com.ydd.framework.core.common.Pagination;
import com.ydd.framework.core.common.dto.ResponseDTO;
import com.ydd.framework.core.controller.BaseApiController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Controller - 场馆课程
 *
 * @author lihong
 * @since 2018-08-06
 */
@RestController
public class VenueLessonController extends BaseApiController {

	private final Logger logger = LoggerFactory.getLogger(VenueLessonController.class);
	
	@Resource
	private VenueLessonService venueLessonService;
	@Resource
	private MemberCardService memberCardService;

	/**
	 * 分页查询场馆课程
	 */
	@RequestMapping(value = "/venue/lessons", method = RequestMethod.GET)
	public ResponseDTO findPage(Pagination pagination) {
		return ResponseDTO.ok()
				.setPagination(venueLessonService.findPage(pagination));
	}

	/**
	 * 查询场馆课程信息
	 */
	@RequestMapping(value = "/venue/lesson/{id}", method = RequestMethod.GET)
	public ResponseDTO findById(@PathVariable("id") Integer id) {
		return ResponseDTO.ok()
				.addAttribute("venueLesson", venueLessonService.findById(id));
	}

	/**
	 * 保存场馆课程
	 */
	@RequestMapping(value = "/venue/lesson", method = RequestMethod.POST)
	public ResponseDTO save(VenueLesson venueLesson) {
		venueLessonService.save(venueLesson);
		return ResponseDTO.ok("保存成功");
	}

	/**
	 * 删除场馆课程
	 */
	@RequestMapping(value = "/venue/lesson/delete", method = RequestMethod.POST)
	public ResponseDTO delete(@RequestParam("id[]") Integer[] ids) {
		venueLessonService.deleteByIds(ids);
		return ResponseDTO.ok("删除成功");
	}

	/**
	 * 查询所有的课程列表，时间
	 */
	@RequestMapping(value = "/venue/lesson/show", method = RequestMethod.GET)
	public ResponseDTO show(@RequestParam("venueId")Integer venueId,@RequestParam("type") Integer type){
		return ResponseDTO.ok().addAttribute("lessons",venueLessonService.show(venueId,type));
	}

    /**
     * 查询上课时间对应的课程
     */
    @RequestMapping(value = "/venue/lesson/date", method = RequestMethod.POST)
    public ResponseDTO lessonShow(@RequestParam("venueId")Integer venueId,
                                  @RequestParam("type")Integer type,
                                  @RequestParam("date") String date){
        return ResponseDTO.ok().addAttribute("venueLessons",venueLessonService.lessonShow(venueId,type,date));
    }

	/**
	 * 课程详情
	 */
	@RequestMapping(value = "/venue/lesson/detail", method = RequestMethod.POST)
	public ResponseDTO detail(@RequestParam("lessonId") Integer lessonId){
		VenueLessonDTO venueLessonDTOS = venueLessonService.findDetail(lessonId);
		return  ResponseDTO.ok().addAttribute("lesson",venueLessonDTOS);
	}

	/**
	 * 预约课程确认订单页面
	 * @param venueId 场馆Id
	 * @param venueType 场馆类型
	 * @param lessonId 课程id
	 * @return
	 */
	@RequestMapping(value = "/venue/lesson/order", method = RequestMethod.POST)
	public ResponseDTO lessonOrder(@RequestParam("venueId")Integer venueId,@RequestParam("venueType")Integer venueType,
								   @RequestParam("lessonId") Integer lessonId){
		;
		return ResponseDTO.ok().
				addAttribute("lessonOrder",venueLessonService.findLessonOrder(getMemberIdByAccessToken(),venueId,venueType,lessonId))
				.addAttribute("memberCard",memberCardService.findMemberCardByVenues(getMemberIdByAccessToken(),venueId,venueType));

	}
}
