package mongo

import (
	"testing"
	"time"
)

func TestConf_DefaultValues(t *testing.T) {
	conf := &Conf{}

	// Test default values
	if conf.Schema != "" {
		t.Errorf("Expected empty Schema, got %s", conf.Schema)
	}
	if conf.User != "" {
		t.Errorf("Expected empty User, got %s", conf.User)
	}
	if conf.Password != "" {
		t.Errorf("Expected empty Password, got %s", conf.Password)
	}
	if conf.Host != "" {
		t.Errorf("Expected empty Host, got %s", conf.Host)
	}
	if conf.Database != "" {
		t.Errorf("Expected empty Database, got %s", conf.Database)
	}
	if conf.ReplicaName != "" {
		t.Errorf("Expected empty ReplicaName, got %s", conf.ReplicaName)
	}
	if conf.MaxStaleness != 0 {
		t.Errorf("Expected zero MaxStaleness, got %v", conf.MaxStaleness)
	}
	if conf.MaxPoolSize != 0 {
		t.Errorf("Expected zero MaxPoolSize, got %d", conf.MaxPoolSize)
	}
	if conf.MinPoolSize != 0 {
		t.Errorf("Expected zero MinPoolSize, got %d", conf.MinPoolSize)
	}
	if conf.MaxConnIdleTime != 0 {
		t.Errorf("Expected zero MaxConnIdleTime, got %v", conf.MaxConnIdleTime)
	}
	if conf.Compressors != nil {
		t.Errorf("Expected nil Compressors, got %v", conf.Compressors)
	}
	if conf.EnableStandardReadWriteSplitMode {
		t.Errorf("Expected false EnableStandardReadWriteSplitMode, got %v", conf.EnableStandardReadWriteSplitMode)
	}
	if conf.ConnectTimeoutMs != 0 {
		t.Errorf("Expected zero ConnectTimeoutMs, got %d", conf.ConnectTimeoutMs)
	}
}

func TestConf_WithValues(t *testing.T) {
	conf := &Conf{
		Schema:                           "mongodb",
		User:                             "testuser",
		Password:                         "testpass",
		Host:                             "localhost:27017",
		Database:                         "testdb",
		ReplicaName:                      "testreplica",
		MaxStaleness:                     30 * time.Second,
		MaxPoolSize:                      100,
		MinPoolSize:                      10,
		MaxConnIdleTime:                  5 * time.Minute,
		Compressors:                      []string{"snappy", "zlib"},
		EnableStandardReadWriteSplitMode: true,
		ConnectTimeoutMs:                 5000,
	}

	// Test set values
	if conf.Schema != "mongodb" {
		t.Errorf("Expected 'mongodb' Schema, got %s", conf.Schema)
	}
	if conf.User != "testuser" {
		t.Errorf("Expected 'testuser' User, got %s", conf.User)
	}
	if conf.Password != "testpass" {
		t.Errorf("Expected 'testpass' Password, got %s", conf.Password)
	}
	if conf.Host != "localhost:27017" {
		t.Errorf("Expected 'localhost:27017' Host, got %s", conf.Host)
	}
	if conf.Database != "testdb" {
		t.Errorf("Expected 'testdb' Database, got %s", conf.Database)
	}
	if conf.ReplicaName != "testreplica" {
		t.Errorf("Expected 'testreplica' ReplicaName, got %s", conf.ReplicaName)
	}
	if conf.MaxStaleness != 30*time.Second {
		t.Errorf("Expected 30s MaxStaleness, got %v", conf.MaxStaleness)
	}
	if conf.MaxPoolSize != 100 {
		t.Errorf("Expected 100 MaxPoolSize, got %d", conf.MaxPoolSize)
	}
	if conf.MinPoolSize != 10 {
		t.Errorf("Expected 10 MinPoolSize, got %d", conf.MinPoolSize)
	}
	if conf.MaxConnIdleTime != 5*time.Minute {
		t.Errorf("Expected 5m MaxConnIdleTime, got %v", conf.MaxConnIdleTime)
	}
	if len(conf.Compressors) != 2 {
		t.Errorf("Expected 2 Compressors, got %d", len(conf.Compressors))
	}
	if conf.Compressors[0] != "snappy" || conf.Compressors[1] != "zlib" {
		t.Errorf("Expected ['snappy', 'zlib'] Compressors, got %v", conf.Compressors)
	}
	if !conf.EnableStandardReadWriteSplitMode {
		t.Errorf("Expected true EnableStandardReadWriteSplitMode, got %v", conf.EnableStandardReadWriteSplitMode)
	}
	if conf.ConnectTimeoutMs != 5000 {
		t.Errorf("Expected 5000 ConnectTimeoutMs, got %d", conf.ConnectTimeoutMs)
	}
}
