package com.liangjian.dataplatform.member.entity.vo.tagrules;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: 黄子奇
 * @Date: 2019/9/21 10:00
 */
public class SqlContext {
    /** 主表（父表）id */
    private String mainPdmId;

    /**
     * join时候的映射关系, 如: ci(id) -> (
     */
    private Map<String, List<RelEntity>> joinColumnsRel;

    /**
     * 表id，表别名映射
     */
    private Map<String,String> tableIdAlias;

    /**
     * 表id，名称映射
     */
    private Map<String,String> tableIdName;

    private Integer type;

    public SqlContext(String mainPdmId, Map<String, List<RelEntity>> joinColumnsRel, Map<String, String> tableIdAlias, Map<String,String> tableIdName) {
        this.tableIdAlias = tableIdAlias;
        this.joinColumnsRel = joinColumnsRel;
        this.tableIdName = tableIdName;
        this.mainPdmId = mainPdmId;
    }

    public String getTableAlias(String id) {
        return tableIdAlias.get(id);
    }

    public List<RelEntity> getRelCols(String id) {
        return joinColumnsRel.get(id);
    }

    public String getTableName(String id) {
        return tableIdName.get(id);
    }

    public Map<String, List<RelEntity>> getJoinColumnsRel() {
        return joinColumnsRel;
    }

    public Map<String, String> getTableIdAlias() {
        return tableIdAlias;
    }

    public String getMainPdmId() {
        return mainPdmId;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public static class RelEntity {
        /** 子关联字段 */
        public String destCol;
        /** 父关联字段 */
        public String srcCol;

        public RelEntity() {
        }

        public RelEntity(String destCol, String srcCol) {
            this.destCol = destCol;
            this.srcCol = srcCol;
        }
    }
}
