package com.copy.trade.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.copy.trade.constant.DogeApi;
import com.copy.trade.entity.base.BaseQueryForm;
import com.copy.trade.entity.form.AgentStudentPositionForm;
import com.copy.trade.entity.form.StudentPositionForm;
import com.copy.trade.entity.po.Customer;
import com.copy.trade.entity.po.Follow;
import com.copy.trade.entity.vo.FolloweInforAgentVo;
import com.copy.trade.entity.vo.FollowerAgentVo;
import com.copy.trade.entity.vo.FollowerVo;
import com.copy.trade.enums.FollowStatusEnum;
import com.copy.trade.enums.TraderEnum;
import com.copy.trade.service.ICustomerService;
import com.copy.trade.service.IFollowService;
import com.copy.trade.util.WebAssert;

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

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 跟随表 前端控制器
 * </p>
 *
 * @author wz
 * @since 2022-11-08
 */
@Api(value = "跟随表", tags = "跟随表")
@RestController
@RequestMapping("/follow")
public class FollowController {

	IFollowService followServiceImpl;

	@Autowired
	private ICustomerService customerServiceImpl;

	/**
	 * 推荐使用构造器注入
	 * @param followServiceImpl
	 */	
	@Autowired
	FollowController(IFollowService followServiceImpl) {
		this.followServiceImpl = followServiceImpl;
	}
	

	public List<Follow> getByCustomerId(Long customerId) {
		return followServiceImpl.getByCustomerId(customerId);
	}
	
	@ApiOperation(value = "我的学生列表")
	@PostMapping("/followers")
	public Page<FollowerVo> followers(@RequestBody StudentPositionForm studentPositionForm){
		Customer customer = customerServiceImpl.getByMemberId(studentPositionForm.getTraderMemberId());
		WebAssert.isTrue(customer.getTrader() == TraderEnum.TRADER.getStatus(),"chk.not.trader");
		studentPositionForm.setTraderId(customer.getId());
		return followServiceImpl.followers(studentPositionForm);
	}
	
	@ApiOperation(value = "代理商的学生列表")
	@PostMapping("/followers-agent")
	public Page<FollowerAgentVo> followersAgent(@RequestBody AgentStudentPositionForm agentStudentPositionForm){
		return followServiceImpl.followersAgent(agentStudentPositionForm);
	}
	
	@ApiOperation(value = "查询代理商下级的跟单信息")
	@PostMapping("/follow-infor-agent")
	public FolloweInforAgentVo selectFollowInforAgent(String subIds){
		return followServiceImpl.selectFollowInforAgent(subIds);
	}
	
	@ApiOperation(value = "移除跟随")
	@PutMapping("/remove-follow")
	public Boolean removeFollow(@RequestParam Long customerId,@RequestParam Long traderId){
		return followServiceImpl.removeFollow(customerId,traderId);
	}
	
}
