package quant.rich.emoney.entity.sqlite;

import java.util.Objects;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import lombok.Data;
import lombok.ToString;
import lombok.experimental.Accessors;

/**
 * 益盟策略和策略池
 * <p>
 * SQLite 表 strategy_and_pool 对 pool_id 设置了 UNIQUE_POOL_ID 唯一约束，并使用
 * ON CONFLICT REPLACE。重复写入同一 pool_id 时会由 SQLite 替换旧记录。
 */
@Data
@Accessors(chain=true)
@TableName(value="strategy_and_pool")
@ToString
public class StrategyAndPool implements Comparable<StrategyAndPool> {
    
    private String strategyName;
    private Integer strategyId;
    private String poolName;
    private String type;
    @TableId
    private Integer poolId;
    
    public StrategyAndPool() {
        
    }
    
    public StrategyAndPool(String type, String strategyName, Integer strategyId, String poolName, Integer poolId) {
        this.type = type;
        this.strategyName = strategyName;
        this.strategyId = strategyId;
        this.poolName = poolName;
        this.poolId = poolId;
    }
    
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null) return false;
        if (!(o instanceof StrategyAndPool)) return false;
        StrategyAndPool strategyAndPool = (StrategyAndPool) o;
        return 
                Objects.equals(strategyName, strategyAndPool.strategyName) &&
                Objects.equals(strategyId, strategyAndPool.strategyId) &&
                Objects.equals(poolName, strategyAndPool.poolName) &&
                Objects.equals(poolId, strategyAndPool.poolId) &&
                Objects.equals(type, strategyAndPool.type);
    }

    @Override
    public int hashCode() {
        return Objects.hash(strategyName, strategyId, poolName, poolId, type);
    }

    /**
     * 排序，先按 strategyId 升序，再按 poolId 升序
     * @param other
     * @return
     */
    @Override
    public int compareTo(StrategyAndPool other) {
        int cmp = Integer.compare(this.strategyId, other.strategyId);
        if (cmp == 0) {
            cmp = Integer.compare(this.poolId, other.poolId);
        }
        return cmp;
    }
}
