package com.sv.oms.controller;

import com.sv.entity.VenueCard;
import com.sv.service.oms.VenueCardService;
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 zhaoziyu
 * @since 2018-08-08
 */
@RestController
public class VenueCardController extends OmsController {

	private final Logger logger = LoggerFactory.getLogger(VenueCardController.class);
	
	@Resource(name = "VenueCardOmsService")
	private VenueCardService venueCardService;

	/**
	 * 分页查询场馆会员卡
	 */
	@RequestMapping(value = "/venue/cards", method = RequestMethod.GET)
	public ResponseDTO findPage(Pagination pagination,@RequestParam("venueId") Integer venueId,@RequestParam("venueType") Integer venueType) {
		return ResponseDTO.ok()
				.setPagination(venueCardService.findPage(pagination,venueId,venueType));
	}

	/**
	 * 查询场馆会员卡
	 */
	@RequestMapping(value = "/venue/cards/card", method = RequestMethod.GET)
	public ResponseDTO findVenueCard(@RequestParam("id") Integer id){
		return ResponseDTO.ok().addAttribute("card",venueCardService.findAlls(id));
	}

	/**
	 * 查询场馆会员卡信息
	 */
	@RequestMapping(value = "/venue/card/{id}", method = RequestMethod.GET)
	public ResponseDTO findsById(@PathVariable("id") Integer id) {
		return ResponseDTO.ok()
				.addAttribute("venueCard", venueCardService.findsById(id));
	}

	/**
	 * 保存场馆会员卡
	 */
	@RequestMapping(value = "/venue/card", method = RequestMethod.POST)
	public ResponseDTO save(VenueCard venueCard) {
		venueCardService.save(venueCard);
		return ResponseDTO.ok("保存成功");
	}

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

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

}
