package com.copy.trade.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

import com.bizzan.bitrade.entity.transform.AuthMember;
import com.copy.trade.constant.DogeApi;
import com.copy.trade.entity.form.MessageConfigForm;
import com.copy.trade.entity.po.MessageConfig;
import com.copy.trade.service.IMessageConfigService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(value = "推送消息接口", tags = "推送消息接口")
@RestController
@RequestMapping("/message-config")
public class MessageConfigController {

	IMessageConfigService configService;
	
	@Autowired
	public MessageConfigController(IMessageConfigService configService) {
		this.configService = configService;
	}
	
	@ApiOperation(value = "获取消息配置")
	@GetMapping("/get")
	public MessageConfig config(@SessionAttribute(DogeApi.SESSION_MEMBER) AuthMember authMember){
		return configService.get(authMember.getId());
	}

	@ApiOperation(value = "设置消息配置")
	@PostMapping("/set")
	public Boolean configSet(@SessionAttribute(DogeApi.SESSION_MEMBER) AuthMember authMember, @RequestBody MessageConfigForm messageConfigForm){
		return configService.update(messageConfigForm, authMember.getId());
	}
}
