package com.copy.trade.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bizzan.bitrade.entity.transform.AuthMember;
import com.copy.trade.constant.DogeApi;
import com.copy.trade.entity.po.Customer;
import com.copy.trade.entity.po.TraderSymbol;
import com.copy.trade.entity.vo.TraderSymbolVo;
import com.copy.trade.enums.TraderEnum;
import com.copy.trade.service.ICustomerService;
import com.copy.trade.service.ITraderSymbolService;
import com.copy.trade.util.BeanCopior;
import com.copy.trade.util.WebAssert;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 交易员带单合约 前端控制器
 * </p>
 *
 * @author wz
 * @since 2022-11-08
 */
@Api(value = "交易员带单合约", tags = "交易员带单合约")
@RestController
@RequestMapping("/trader-symbol")
public class TraderSymbolController {

	ITraderSymbolService traderSymbolServiceImpl;

	@Autowired
	private ICustomerService customerServiceImpl;

	/**
	 * 推荐使用构造器注入
	 * @param traderSymbolServiceImpl
	 */	
	@Autowired
	TraderSymbolController(ITraderSymbolService traderSymbolServiceImpl) {
		this.traderSymbolServiceImpl = traderSymbolServiceImpl;
	}

	@ApiOperation(value = "更新带单合约交易对")
	@ApiImplicitParam(name = "symbolList", value = "交易对数组",required = true,allowMultiple=true,dataType = "string")
	@PostMapping("/update")
	public Boolean update(@SessionAttribute(DogeApi.SESSION_MEMBER) AuthMember authMember, @RequestBody List<String> symbolList){
		Customer trader = customerServiceImpl.getByMemberId(authMember.getId());
		WebAssert.isTrue(TraderEnum.TRADER.getStatus().equals(trader.getTrader()),"chk.not.trader");
		return traderSymbolServiceImpl.update(trader.getId(),symbolList);
	}

	@ApiOperation(value = "交易员带单交易对列表")
	@PutMapping("/{traderId}")
	public List<TraderSymbolVo> list(@PathVariable Long traderId){
		QueryWrapper<TraderSymbol> traderSymbolQueryWrapper = new QueryWrapper<>();
		traderSymbolQueryWrapper.eq("trader_id",traderId);
		List<TraderSymbol> list = traderSymbolServiceImpl.list(traderSymbolQueryWrapper);
		return BeanCopior.mapList(list, TraderSymbolVo.class);
	}


}
