package initialize

import (
	"github.com/caarlos0/env/v8"
	"github.com/joho/godotenv"
	"log"
)

type Config struct {
  MongoURL         string `env:"MONGO_URL" envDefault:"localhost:27017"`
  DatabaseName     string `env:"MONGO_DB_NAME" envDefault:"support"`
	NumberPortLocal  string `env:"BB_PORT" envDefault:"1488"`
	AccountAddress   string `env:"BB_AccountAddress" envDefault:":8931"`
	LoggerDevMode    bool   `env:"BB_IS_PROD" envDefault:"false"`
	MinioEndpoint    string `env:"BB_MINIO_EP" envDefault:"localhost:9000"`
	MinioAccessKey   string `env:"BB_MINIO_AK" envDefault:"minioadmin"`
	MinioSecretKey   string `env:"BB_MINIO_SK" envDefault:"minioadmin"`
	MinioRegion      string `env:"S3_REGION" envDefault:""`
	MinioToken       string `env:"BB_MINIO_TOKEN" envDefault:""`
	MongoDbTable     string `env:"DATABASE_TABLE" envDefault:"profile"`
	MongoCollections string `env:"COLLECTION_NAME" envDefault:"profile,role"`
	TgToken          string `env:"TELEGRAM_TOKEN" envDefault:"7127966184:AAG1steOCH4wDvHRe9QcsXJPS4dWRyRYsqg"`
	RedisHost        string `env:"REDIS_HOST" envDefault:"localhost:6379"`
	RedisPassword    string `env:"REDIS_PASSWORD" envDefault:"admin"`
	RedisDB          int    `env:"REDIS_DB" envDefault:"2"`
	TgChatID         int64 `env:"TELEGRAM_CHAT_ID" envDefault:"1001344671794"`
	HTTPHost         string `env:"HTTP_HOST" envDefault:"localhost"`
	HTTPPort         string `env:"HTTP_PORT" envDefault:"3000"`
}

func LoadConfig() (*Config, error) {
	if err := godotenv.Load(); err != nil {
		log.Print("No .env file found")
	}
	var config Config
	if err := env.Parse(&config); err != nil {
		return nil, err
	}
	return &config, nil
}
