package validator

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

type TestStruct struct {
	Name  string `validate:"required"`
	Email string `validate:"required,email"`
	Age   int    `validate:"min=0,max=150"`
}

func TestValidate_ValidStruct(t *testing.T) {
	s := TestStruct{Name: "John", Email: "john@example.com", Age: 25}
	err := Validate(s)
	assert.NoError(t, err)
}

func TestValidate_MissingRequired(t *testing.T) {
	s := TestStruct{Email: "john@example.com", Age: 25}
	err := Validate(s)
	assert.Error(t, err)
}

func TestValidate_InvalidEmail(t *testing.T) {
	s := TestStruct{Name: "John", Email: "not-an-email", Age: 25}
	err := Validate(s)
	assert.Error(t, err)
}

func TestValidate_AgeOutOfRange(t *testing.T) {
	s := TestStruct{Name: "John", Email: "john@example.com", Age: 200}
	err := Validate(s)
	assert.Error(t, err)
}

func TestGet_ReturnsInstance(t *testing.T) {
	v := Get()
	assert.NotNil(t, v)
	// 多次调用应返回相同实例
	v2 := Get()
	assert.Equal(t, v, v2)
}
