package org.lym.pom.config;

import org.shoulder.web.template.dictionary.convert.PackageScanDictionaryItem2StrConverterMongoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.config.MongoConfigurationSupport;
import org.springframework.data.mongodb.core.convert.MongoCustomConversions.MongoConverterConfigurationAdapter;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

@Configuration
//@EnableMongoRepositories("org.lym.pom.repository")
public class MongoConfig extends MongoConfigurationSupport {

    @Override protected String getDatabaseName() {
        // todo dbName
        return "moments";
    }

    @Override
    protected Collection<String> getMappingBasePackages() {
        return List.of("org.lym.pom.repository");
    }

    @Override
    public boolean autoIndexCreation() {
        return true;
    }

    @Override protected void configureConverters(MongoConverterConfigurationAdapter converterConfigurationAdapter) {

        converterConfigurationAdapter.configurePropertyConversions(propertyValueConverterRegistrar -> {
            new PackageScanDictionaryItem2StrConverterMongoConfiguration(Collections.singleton("org.lym.pom.repository.mongo"));
        });
    }

    //@Bean
    //public MongoCustomConversions mongoCustomConversions() {
    //  return MongoCustomConversions.create(config -> config.configurePropertyConversions(pvcr-> {
    //    pvcr.registerConverter(Post.class, "", new EnumToStringConverter());
    //  }));
    //}

}