package models

import (
	"time"

	"github.com/golang-jwt/jwt/v5"
	"penahub.gitlab.yandexcloud.net/backend/penahub_common/mongo"
)

type Config struct {
	HTTP     ConfigurationHTTP
	GRPC     ConfigurationGRPC
	Service  ServiceConfiguration
	Database mongo.Configuration
}

type ConfigurationHTTP struct {
	ClientHost string `env:"CLIENT_HTTP_HOST,default=localhost"`
	ClientPort string `env:"CLIENT_HTTP_PORT,default=8080"`
	AdminHost  string `env:"ADMIN_HTTP_HOST,default=localhost"`
	AdminPort  string `env:"ADMIN_HTTP_PORT,default=8081"`
}

type ConfigurationGRPC struct {
	Host  string `env:"GRPC_HOST,default=localhost"`
	Port  string `env:"GRPC_PORT,default=8081"`
	Domen string `env:"GRPC_DOMEN,default=https://domen.ru"`
}

type ServiceConfiguration struct {
	AuthMicroservice           AuthMicroserviceConfiguration
	HubadminMicroservice       HubadminMicroserviceConfiguration
	CurrencyMicroservice       CurrencyMicroserviceConfiguration
	DiscountMicroservice       DiscountMicroserviceConfiguration
	CodewordMicroservice       CodewordMicroserviceConfiguration
	PaymentMicroservice        PaymentMicroserviceConfiguration
	VerificationMicroservice   VerificationMicroserviceConfiguration
	TemplategenMicroserviceURL TemplategenMicroserviceConfiguration
	JWT                        JWTConfiguration
	Kafka                      KafkaConfiguration
	Mail                       MailConfiguration
	TrashLogHost               string `env:"TRASH_LOG_HOST"`
	PubKey                     string `env:"PUBLIC_KEY"`
	PrivKey                    string `env:"PRIVATE_KEY"`
	ModuleLogger               string `env:"MODULE_LOGGER"`
	NotificationBotToken       string `env:"NOTIFICATION_BOT_TOKEN"`
	NotificationChannel        int64  `env:"NOTIFICATION_CHANNEL"`
	AdminURL                   string `env:"ADMIN_FRONT_URL"`
}

type KafkaConfiguration struct {
	Tariff  TariffKafkaConfiguration `json:"tariff"`
	Brokers []string                 `json:"brokers" env:"KAFKA_BROKERS,required"`
}

type TariffKafkaConfiguration struct {
	Topic string `json:"topic" env:"KAFKA_TOPIC_TARIFF,required"`
}

type JWTConfiguration struct {
	PrivateKey string `env:"JWT_PRIVATE_KEY"`
	PublicKey  string `env:"JWT_PUBLIC_KEY,required"`
	Issuer     string `env:"JWT_ISSUER,required"`
	Audience   string `env:"JWT_AUDIENCE,required"`
	Algorithm  jwt.SigningMethodRSA
	ExpiresIn  time.Duration
}

type AuthMicroserviceConfiguration struct {
	URL AuthMicroserviceURL
}

type HubadminMicroserviceConfiguration struct {
	URL HubadminMicroserviceURL
}

type CurrencyMicroserviceConfiguration struct {
	URL CurrencyMicroserviceURL
}

type VerificationMicroserviceConfiguration struct {
	URL VerificationMicroserviceURL
}

type TemplategenMicroserviceConfiguration struct {
	URL TemplategenMicroserviceURL
}

type CodewordMicroserviceConfiguration struct {
	HostGRPC string `env:"CODEWORD_MICROSERVICE_GRPC_HOST,required"`
}

type PaymentMicroserviceConfiguration struct {
	HostGRPC string `env:"PAYMENT_MICROSERVICE_GRPC_HOST,required"`
}

type DiscountMicroserviceConfiguration struct {
	HostGRPC string `env:"DISCOUNT_MICROSERVICE_GRPC_HOST,required"`
}

type AuthMicroserviceURL struct {
	User string `env:"AUTH_MICROSERVICE_USER_URL,required"`
}

type HubadminMicroserviceURL struct {
	Tariff string `env:"HUBADMIN_MICROSERVICE_TARIFF_URL,required"`
}

type CurrencyMicroserviceURL struct {
	Translate string `env:"CURRENCY_MICROSERVICE_TRANSLATE_URL,required"`
}

type VerificationMicroserviceURL struct {
	Verification string `env:"VERIFICATION_MICROSERVICE_USER_URL,required"`
}

type TemplategenMicroserviceURL struct {
	Templategen string `env:"TEMPLATEGEN_MICROSERVICE_URL,required"`
}

type MailConfiguration struct {
	ApiUrl      string `env:"API_URL,required"`
	Sender      string `env:"MAIL_SENDER,required"`
	Auth        PlainAuth
	ApiKey      string `env:"MAIL_API_KEY,required"`
	MailAddress string `env:"MAIL_ADDRESS,required"`
}

type PlainAuth struct {
	Identity string `env:"MAIL_AUTH_IDENTITY"`
	Username string `env:"MAIL_AUTH_USERNAME,required"`
	Password string `env:"MAIL_AUTH_PASSWORD,required"`
}

const mongoVersion uint32 = 1
