package com.sv.oms.controller;
import com.sv.service.common.VipCardService;
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 com.sv.entity.VipCard;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Controller - 会员卡
 *
 * @author yechanglin
 * @since 2018-08-11
 */
@RestController
public class VipCardController extends OmsController {

	private final Logger logger = LoggerFactory.getLogger(VipCardController.class);
	
	@Resource
	private VipCardService vipCardService;

	/**
	 * 分页查询会员卡
	 */
	@RequestMapping(value = "/vip/cards", method = RequestMethod.GET)
	public ResponseDTO findPage(Pagination pagination) {
		return ResponseDTO.ok().addAttribute("cards",vipCardService.findAll());
	}

	/**
	 * 查询会员卡信息
	 */
	@RequestMapping(value = "/vip/card/{id}", method = RequestMethod.GET)
	public ResponseDTO findById(@PathVariable("id") Integer id) {
		return ResponseDTO.ok()
				.addAttribute("vipCard", vipCardService.findById(id));
	}

	/**
	 * 查询会员卡
	 */
	@RequestMapping(value = "/vip/cards/card", method = RequestMethod.GET)
	public ResponseDTO findCard(){
		return ResponseDTO.ok().addAttribute("card",vipCardService.findAll());
	}


	/**
	 * 保存会员卡
	 */
	@RequestMapping(value = "/vip/card", method = RequestMethod.POST)
	public ResponseDTO save(VipCard vipCard) {
		vipCardService.save(vipCard);
		return ResponseDTO.ok("保存成功");
	}

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

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

}
