package com.datacenter.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.datacenter.job.vo.FollowerCleanupCandidateVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
@DS("copytrade")
public interface FollowerCleanupMapper {

    /**
     * 查询需要清理的跟单员列表：
     * 跟单余额 < 交易员配置的最小跟单金额，且当前无持仓（未平仓或部分平仓）。
     * 详细 SQL 见 FollowerCleanupMapper.xml
     */
    List<FollowerCleanupCandidateVo> findCandidates();

    /** 将跟随状态置为已移出（30 = 被交易员移出） */
    @Update("UPDATE follow SET status = 30, updated_time = NOW() WHERE id = #{followId}")
    void removeFollow(@Param("followId") Long followId);

    /** 删除该跟随关系下的所有风险控制交易对 */
    @Delete("DELETE FROM customer_follow_symbol " +
            "WHERE risk_control_id IN (SELECT id FROM risk_control WHERE follow_id = #{followId})")
    void deleteFollowSymbols(@Param("followId") Long followId);

    /** 删除该跟随关系的风险控制记录 */
    @Delete("DELETE FROM risk_control WHERE follow_id = #{followId}")
    void deleteRiskControl(@Param("followId") Long followId);
}
