/**
 * 用于创建所需的ParseService。
 */
import {ParseService} from "./parseService";
import {EditorContext} from "..";
import {GlobalConstant} from "../constant/globalConstant";
import {MysqlParseService} from "./impl/mysql/mysqlParseService";
import {SymbolTable} from "../symbols/symbolTable";
import {OracleParseService} from "./impl/oracle/oracleParseService";

export class ParseServiceFactory {


    /**
     * 根据传入的输入上下文，创建所需的ParseService具体实现
     * @param editorContext
     */
    public static createParseService(editorContext: EditorContext):ParseService{
        let parseService:ParseService;

        switch (editorContext.dataSourceName) {
            case GlobalConstant.DATASOURCE_MYSQL:
                parseService = ParseServiceFactory.createMySQlParseService(editorContext);
                break;
            case GlobalConstant.DATASOURCE_TIDB:
                parseService = ParseServiceFactory.createMySQlParseService(editorContext);
                break;
            case GlobalConstant.DATASOURCE_SHARDING:
                parseService = ParseServiceFactory.createMySQlParseService(editorContext);
                break;
            case GlobalConstant.DATASOURCE_ORACLE:
                parseService = ParseServiceFactory.createOracleParseService(editorContext);
                break;
            default:
                console.log("error:暂时无法识别的数据源类型-"+editorContext.dataSourceName);
                break;

        }

        parseService.editorContext = editorContext;
        parseService.symbolTable = new SymbolTable();

        return parseService;
    }

    private static createMySQlParseService(editorContext: EditorContext):ParseService {
        return new MysqlParseService();
    }

    private static createOracleParseService(editorContext: EditorContext):ParseService {
       return new OracleParseService();
    }
}