package com.sv.oms.controller;

import com.sv.entity.MemberLessonTicket;
import com.sv.service.oms.MemberLessonTicketService;
import com.ydd.framework.core.common.Pagination;
import com.ydd.framework.core.common.dto.ResponseDTO;
import com.ydd.framework.core.entity.enums.StatusEnum;
import com.ydd.oms.controller.OmsController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Controller - 预约场馆课程订单
 *
 * @author yechanglin
 * @since 2018-08-03
 */
@RestController
public class MemberLessonTicketController extends OmsController {

	private final Logger logger = LoggerFactory.getLogger(MemberLessonTicketController.class);
	
	@Resource
	private MemberLessonTicketService memberLessonTicketService;

	/**
	 * 分页查询预约场馆课程订单
	 */
	@RequestMapping(value = "/member/lesson/tickets", method = RequestMethod.GET)
	public ResponseDTO findPage(Pagination pagination,
								@RequestParam(value = "payStatus",required = false) Integer payStatus,
								@RequestParam(value = "starTime",required = false) String starTime,
								@RequestParam(value = "endTime",required = false) String endTime,
								@RequestParam(value = "orderSn",required = false) String orderSn,
								@RequestParam(value = "lessonname",required = false) String lessonname,
								@RequestParam(value = "lessonId",required = false) Integer lessonId) {
		return ResponseDTO.ok()
				.setPagination(memberLessonTicketService.findPage(pagination, payStatus, starTime, endTime, orderSn, lessonname, lessonId));
	}

	/**
	 * 查询预约场馆课程订单信息
	 */
	@RequestMapping(value = "/member/lesson/ticket/{id}", method = RequestMethod.GET)
	public ResponseDTO findById(@PathVariable("id") Integer id) {
		return ResponseDTO.ok()
				.addAttribute("memberLessonTicket", memberLessonTicketService.findById(id));
	}

	/**
	 * 保存预约场馆课程订单
	 */
	@RequestMapping(value = "/member/lesson/ticket", method = RequestMethod.POST)
	public ResponseDTO save(MemberLessonTicket memberLessonTicket) {
		memberLessonTicketService.save(memberLessonTicket);
		return ResponseDTO.ok("保存成功");
	}

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

	/**
	 * 变更预约场馆课程订单状态
	 */
	@RequestMapping(value = "/member/lesson/ticket/status", method = RequestMethod.POST)
	public ResponseDTO updateStatus(@RequestParam("id[]") Integer[] ids, Byte status) {
		memberLessonTicketService.updateStatus(ids, status);
		String operationName = (StatusEnum.ENABLE.value.equals(status) ? "启用" : "禁用") + "成功";
		return ResponseDTO.ok(operationName);
	}

}
