package com.sv.oms.controller;
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.GiftMemberCard;
import com.sv.service.oms.GiftMemberCardService;

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

import javax.annotation.Resource;

/**
 * Controller - 送会员卡记录
 *
 * @author yechanglin
 * @since 2018-08-17
 */
@RestController
public class GiftMemberCardController extends OmsController {

	private final Logger logger = LoggerFactory.getLogger(GiftMemberCardController.class);
	
	@Resource
	private GiftMemberCardService giftMemberCardService;

	/**
	 * 分页查询送会员卡记录
	 */
	@RequestMapping(value = "/gift/member/cards", method = RequestMethod.GET)
	public ResponseDTO findPage(Pagination pagination, String name) {
		return ResponseDTO.ok()
				.setPagination(giftMemberCardService.findPage(pagination, name));
	}

	/**
	 * 查询送会员卡记录信息
	 */
	@RequestMapping(value = "/gift/member/card/{id}", method = RequestMethod.GET)
	public ResponseDTO findById(@PathVariable("id") Integer id) {
		return ResponseDTO.ok()
				.addAttribute("giftMemberCard", giftMemberCardService.findById(id));
	}

	/**
	 * 保存送会员卡记录
	 */
	@RequestMapping(value = "/gift/member/card", method = RequestMethod.POST)
	public ResponseDTO save(GiftMemberCard giftMemberCard) {
		giftMemberCardService.save(giftMemberCard);
		return ResponseDTO.ok("保存成功");
	}

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

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

}
