package com.sv.api.controller;

import com.sv.entity.VenueLessonTicket;
import com.sv.service.api.VenueLessonTicketService;
import com.ydd.framework.core.common.Pagination;
import com.ydd.framework.core.common.dto.ResponseDTO;
import com.ydd.framework.core.controller.BaseApiController;
import com.ydd.framework.core.entity.enums.StatusEnum;
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 VenueLessonTicketController extends BaseApiController {

	private final Logger logger = LoggerFactory.getLogger(VenueLessonTicketController.class);
	
	@Resource
	private VenueLessonTicketService venueLessonTicketService;

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

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

	/**
	 * 保存场馆课程票号
	 */
	@RequestMapping(value = "/venue/lesson/ticket", method = RequestMethod.POST)
	public ResponseDTO save(VenueLessonTicket venueLessonTicket) {
		venueLessonTicketService.save(venueLessonTicket);
		return ResponseDTO.ok("保存成功");
	}

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

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

}
