package com.copy.trade.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bizzan.bitrade.entity.transform.AuthMember;
import com.copy.trade.constant.DogeApi;
import com.copy.trade.entity.base.BaseQueryForm;
import com.copy.trade.entity.form.LeadOrderForm;
import com.copy.trade.entity.po.Customer;
import com.copy.trade.entity.vo.FollowOrderVo;
import com.copy.trade.service.ICustomerService;
import com.copy.trade.service.IPositionService;
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 javax.validation.Valid;

/**
 * <p>
 * 跟单持仓表 前端控制器
 * </p>
 *
 * @author wz
 * @since 2022-11-17
 */
@Api(value = "跟单持仓表", tags = "跟单持仓表")
@RestController
@RequestMapping("/position")
public class PositionController {

	IPositionService positionServiceImpl;

	@Autowired
	private ICustomerService customerServiceImpl;

	/**
	 * 推荐使用构造器注入
	 * @param positionServiceImpl
	 */	
	@Autowired
	PositionController(IPositionService positionServiceImpl) {
		this.positionServiceImpl = positionServiceImpl;
	}

	@ApiOperation(value = "当前跟单(收益率计算方式:收益率=当前盈利*100/保证金)",notes = "当前跟单")
	@ApiImplicitParam(name = "baseQueryForm",value = "分页表单",dataType = "BaseQueryForm")
	@PostMapping("/current-follow")
	public Page<FollowOrderVo> currentFollow(@SessionAttribute(DogeApi.SESSION_MEMBER) AuthMember authMember, @RequestBody BaseQueryForm baseQueryForm){
		Customer customer = customerServiceImpl.getByMemberId(authMember.getId());
		return positionServiceImpl.currentFollow(customer.getId(), baseQueryForm.newFormPage());
	}

	@ApiOperation(value = "历史跟单",notes = "历史跟单")
	@ApiImplicitParam(name = "baseQueryForm",value = "分页表单",dataType = "BaseQueryForm")
	@PostMapping("/history-follow")
	public Page<FollowOrderVo> historyFollow(@SessionAttribute(DogeApi.SESSION_MEMBER) AuthMember authMember, @RequestBody BaseQueryForm baseQueryForm){
		Customer customer = customerServiceImpl.getByMemberId(authMember.getId());
		return positionServiceImpl.historyFollow(customer.getId(), baseQueryForm.newFormPage());
	}

	@ApiOperation(value = "交易员带单列表",notes = "交易员带单列表")
	@ApiImplicitParam(name = "leadOrderForm",value = "带单查询表单",dataType = "LeadOrderForm")
	@PostMapping("/lead")
	public Page<FollowOrderVo> lead(@SessionAttribute(DogeApi.SESSION_MEMBER) AuthMember authMember, @RequestBody @Valid LeadOrderForm leadOrderForm){
		Customer customer = customerServiceImpl.getByMemberId(authMember.getId());
		return positionServiceImpl.lead(leadOrderForm.getTraderId(), leadOrderForm.newFormPage(), leadOrderForm.getType());
	}

}
