package com.copy.trade.service;

import com.copy.trade.entity.dto.ClosePositionDeal;
import com.copy.trade.entity.dto.ContractOrderEntrust;
import com.copy.trade.entity.dto.EntrustCallback;
import com.copy.trade.entity.dto.TraderClosePosition;
import com.copy.trade.entity.form.ClosePositionForm;
import com.copy.trade.entity.form.PositionForm;
import com.copy.trade.entity.po.ClosePosition;
import com.copy.trade.entity.vo.ClosePositionVo;
import com.copy.trade.entity.vo.PositionVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;

import java.util.List;

/**
 * <p>
 * 平仓记录 服务类
 * </p>
 *
 * @author wz
 * @since 2022-11-22
 */
public interface IClosePositionService extends IService<ClosePosition> {

    Boolean traderClosePosition(TraderClosePosition traderClosePosition);
    
    public Integer traderClosePositionSuccess(ContractOrderEntrust contractOrderEntrust);

    Boolean followClosePositionCallback(ContractOrderEntrust contractOrderEntrust);

    Boolean cancel(String contractClosePositionEntrustNo);

    Boolean closePositionDeal(ClosePositionDeal closePositionDeal);

    List<ClosePosition> closePositionByPositionId(Long positionId);
    
    Page<ClosePositionVo> list(ClosePositionForm closePositionForm);

    void processCloseRetryQueue();

    Integer doClosePositionDB(ContractOrderEntrust contractOrderEntrust);

    /**
     * 开仓数据丢失时，重建开仓+平仓组合记录（直接写入 DONE 状态的 Position 和成功的 ClosePosition）
     */
    void reconstructOpenAndClose(ContractOrderEntrust contractOrderEntrust);
}
