package com.copy.trade.controller;



import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.copy.trade.entity.base.BaseQueryForm;
import com.copy.trade.entity.form.TraderForm;
import com.copy.trade.entity.form.TraderQueryForAdminForm;
import com.copy.trade.entity.po.Customer;
import com.copy.trade.entity.vo.CustomerVo;
import com.copy.trade.entity.vo.TraderTotalVo;
import com.copy.trade.service.ICustomerService;
import com.copy.trade.util.WebAssert;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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("/customer")
public class CustomerController {

	private final Logger log = LoggerFactory.getLogger(CustomerController.class);

	ICustomerService customerServiceImpl;


	/**
	 * 推荐使用构造器注入
	 * @param customerServiceImpl
	 */
	@Autowired
	CustomerController(ICustomerService customerServiceImpl) {
		this.customerServiceImpl = customerServiceImpl;
	}
	
	@ApiOperation(value = "交易员列表")
	@PostMapping("/trader-list")
	public Page<CustomerVo> traderList(@RequestBody TraderQueryForAdminForm traderQueryForAdminForm){
		return customerServiceImpl.traderList(traderQueryForAdminForm);
	}
	
	@ApiOperation(value = "交易员汇总列表")
	@PostMapping("/trader-total-list")
	public Page<TraderTotalVo> traderTotalList(@RequestBody TraderQueryForAdminForm traderQueryForAdminForm){
		return customerServiceImpl.traderTotalList(traderQueryForAdminForm);
	}
	
	@ApiOperation(value = "取消交易员")
	@PutMapping("/cancel-trader/{traderId}")
	public Boolean approvalTrader(@PathVariable Long traderId){
		return customerServiceImpl.cancelTrader(traderId);

	}
	
	@ApiOperation(value = "修改交易员等级")
	@PutMapping("/update-trader-level/{traderId}/{levelId}")
	public Boolean updateTraderLevel(@PathVariable Long traderId, @PathVariable Long levelId){
		return customerServiceImpl.updateTraderLevelId(traderId, levelId);

	}

	@ApiOperation(value = "设置顶级交易员(1是 2否)")
	@PutMapping("/update-trader-top/{traderId}/{isTop}")
	public Boolean updateTraderTop(@PathVariable Long traderId, @PathVariable Integer isTop){
		return customerServiceImpl.updateTraderTop(traderId, isTop);
	}
	
	@ApiOperation(value = "修改交易员的配置参数")
	@PutMapping("/update-trader-params/{traderId}")
	public Boolean updateTraderParams(@PathVariable Long traderId,@RequestBody TraderForm traderForm){
		return customerServiceImpl.updateTraderParams(traderId, traderForm);
		
	}
	
	@ApiOperation(value = "交易员申请列表")
	@PostMapping("/applying-list")
	public Page<Customer> applyingList(@RequestBody BaseQueryForm baseQueryForm){
		return customerServiceImpl.applyList(baseQueryForm.newFormPage());
	}

	@ApiOperation(value = "批准交易员申请")
	@PutMapping("/approval-trader/{traderId}/{levelId}")
	public Boolean approvalTrader(@PathVariable Long traderId, @PathVariable Long levelId){
		return customerServiceImpl.approvalTrader(traderId,levelId);

	}

	@ApiOperation(value = "拒绝交易员申请")
	@PutMapping("/reject-trader/{traderId}")
	public Boolean rejectTrader(@PathVariable Long traderId){
		return customerServiceImpl.reject(traderId);
	}
	
	@ApiOperation(value = "同步交易员昵称和头像")
	@PostMapping("/synchronous-infor")
	public Boolean synchronousTraderInfor(){
		return customerServiceImpl.synchronousTraderInfor();
	}

}
