package com.sikey.wa04.business.infrastructure.configuration;

import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

@Configuration
@ConfigurationProperties("spring.datasource.druid")
@Data
public class DruidDatasourceConfig {
    private Integer initialSize;
    private Integer minIdle;
    private Integer maxActive;
    private Integer maxWait;
    private Integer timeBetweenEvictionRunsMillis;
    private Integer minEvictableIdleTimeMillis;
    private String validationQuery;
    private Boolean testWhileIdle;
    private Boolean testOnBorrow;
    private Boolean testOnReturn;
    private Boolean poolPreparedStatements;
    private Integer maxPoolPreparedStatementPerConnectionSize;
    private String filters;
    private DruidDatasourceFilterConfig filter;
    private String connectionProperties;

    @Data
    private static class DruidDatasourceFilterConfig {
        private DruidDatasourceFilterStatConfig stat;

        @Data
        private static class DruidDatasourceFilterStatConfig {
            private Boolean enabled;
            private Boolean logSlowSql;
            private Integer slowSqlMillis;
            private Boolean mergeSql;
        }
    }
}
