package io.delphiplatform.api.v3.rdb.service;

import org.hibernate.dialect.function.StandardSQLFunction;
import org.hibernate.type.StandardBasicTypes;

import java.sql.Types;

import io.delphiplatform.api.v3.constant.DbFunctionNamesConstants;
import io.delphiplatform.api.v3.rdb.entity.converter.CustomStringArrayType;

public class CustomPostgresDialect extends org.hibernate.dialect.PostgreSQL10Dialect {

    public CustomPostgresDialect() {
        super();
        registerFunction(DbFunctionNamesConstants.AGGREGATE_FUNCTION_DIV_SUM_BY_CURRENCY,
            new StandardSQLFunction(DbFunctionNamesConstants.AGGREGATE_FUNCTION_DIV_SUM_BY_CURRENCY,
                StandardBasicTypes.STRING)
        );
        registerFunction(DbFunctionNamesConstants.AGGREGATE_FUNCTION_SUM_BY_CURRENCY,
            new StandardSQLFunction(DbFunctionNamesConstants.AGGREGATE_FUNCTION_SUM_BY_CURRENCY,
                StandardBasicTypes.STRING)
        );
        this.registerHibernateType(Types.ARRAY, CustomStringArrayType.class.getName());
    }
}
