package initialize

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

type Config struct {
	ServiceName                string `env:"SERVICE_NAME" envDefault:"squiz"`
	KafkaBrokers               string `env:"KAFKA_BROKERS" envDefault:"localhost:6379"`
	KafkaTopicTariff           string `env:"KAFKA_TOPIC_TARIFF" envDefault:"test-topic"`
	LoggerProdMode             bool   `env:"IS_PROD_LOG" envDefault:"false"`
	IsProd                     bool   `env:"IS_PROD" envDefault:"false"`
	S3Endpoint                 string `env:"S3_ENDPOINT" envDefault:"localhost:3002"`
	S3AccessKey                string `env:"S3_ACCESS_KEY" envDefault:"minio"`
	S3SecretKey                string `env:"S3_SECRET_KEY" envDefault:"miniostorage"`
	PostgresURL                string `env:"POSTGRES_URL" envDefault:"host=localhost port=5432 user=squiz password=Redalert2 dbname=squiz sslmode=disable"`
	RedisHost                  string `env:"REDIS_HOST"`
	RedisPassword              string `env:"REDIS_PASSWORD"`
	RedisDB                    uint64 `env:"REDIS_DB"`
	Sender                     string `env:"MAIL_SENDER" envDefault:"noreply@mailing.pena.digital"`
	ApiKey                     string `env:"MAIL_API_KEY" envDefault:"P0YsjUB137upXrr1NiJefHmXVKW1hmBWlpev"`
	ApiUrl                     string `env:"API_URL" envDefault:"https://api.smtp.bz/v1/smtp/send"`
	CustomerMicroserviceRPCURL string `env:"CUSTOMER_MICROSERVICE_RPC_URL" envDefault:"localhost:9001"`
	TelegramToken              string `env:"TELEGRAM_TOKEN"`

	KafkaTopicGigaChat string `env:"KAFKA_TOPIC_GIGA_CHAT"`
	KafkaGroupGigaChat string `env:"KAFKA_GROUP_GIGA_CHAT" default:"gigachat"`
	GigaChatApiBaseURL string `env:"GIGA_CHAT_API_BASE_URL"`
	GigaChatApiAuthKey string `env:"GIGA_CHAT_API_AUTH_KEY"`

	NotifyTelegramToken string `env:"NOTIFY_TELEGRAM_TOKEN"`
	NotifyChannelID     int64  `env:"NOTIFY_CHANNEL_ID"`
}

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
}
