package com.sv.oms.controller;
import com.sv.entity.VenueType;
import com.sv.service.oms.VenueTypeService;
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 zuojie.Liang
 * @since 2018-08-02
 */
@RestController
public class VenueTypeController extends OmsController {

	private final Logger logger = LoggerFactory.getLogger(VenueTypeController.class);
	
	@Resource
	private VenueTypeService venueTypeService;

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

	/**
	 * 查询场馆类型信息
	 */
	@RequestMapping(value = "/venue/type/{id}", method = RequestMethod.GET)
	public ResponseDTO findById(@PathVariable("id") Integer id) {
		return ResponseDTO.ok()
				.addAttribute("venueType", venueTypeService.findById(id));
	}

	/**
	 * 保存场馆类型
	 */
	@RequestMapping(value = "/venue/type", method = RequestMethod.POST)
	public ResponseDTO save(VenueType venueType) {
		venueTypeService.save(venueType);
		return ResponseDTO.ok("保存成功");
	}

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

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

	/**
	 * 查询所有场馆类型
	 */
	@RequestMapping(value = "/venue/typeAll", method = RequestMethod.GET)
	public ResponseDTO findTypeAll() {
		return ResponseDTO.ok()
				.addAttribute("venueTypes", venueTypeService.findTypeAll());
	}

}
