package org.springblade.datasource.transform.seatunnel;

import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.Getter;

import java.util.Arrays;


@Getter
public enum MysqlToSeatunnelEnum {
    STRING(SeatunnelColumnType.STRING, new String[]{"char", "varchar", "text", "blob", "longtext"}),
    TINYINT(SeatunnelColumnType.TINYINT, new String[]{"tinyint"}),
    SMALLINT(SeatunnelColumnType.SMALLINT, new String[]{"smallint"}),
    INT(SeatunnelColumnType.INT, new String[]{"int"}),
    LONG(SeatunnelColumnType.LONG, new String[]{"bigint"}),
    FLOAT(SeatunnelColumnType.FLOAT, new String[]{"float"}),
    DOUBLE(SeatunnelColumnType.DOUBLE, new String[]{"double"}),
    DECIMAL(SeatunnelColumnType.DECIMAL, new String[]{"numeric", "decimal"}),
    BYTES(SeatunnelColumnType.BYTES, new String[]{"bit"}),
    DATE(SeatunnelColumnType.DATE, new String[]{"date"}),
    TIME(SeatunnelColumnType.TIME, new String[]{"time"}),
    TIMESTAMP(SeatunnelColumnType.TIMESTAMP, new String[]{"timestamp", "datetime"});


    @EnumValue
    private final SeatunnelColumnType seatunnelColumnType;
    private final String[] types;


    MysqlToSeatunnelEnum(SeatunnelColumnType seatunnelColumnType, String[] types) {
        this.seatunnelColumnType = seatunnelColumnType;
        this.types = types;
    }

    public static SeatunnelColumnType transform(String columnType) {
        MysqlToSeatunnelEnum[] values = MysqlToSeatunnelEnum.values();
        for (MysqlToSeatunnelEnum mysqlToSeatunnelEnum : values) {
            if (Arrays.asList(mysqlToSeatunnelEnum.getTypes()).contains(columnType)) {
                return mysqlToSeatunnelEnum.getValue();

            }
        }
        return null;
    }

    /**
     * @return the value
     */
    public SeatunnelColumnType getValue() {
        return seatunnelColumnType;
    }

    /**
     * @return the types
     */
    public String[] getTypes() {
        return types;
    }
}
