package models

import (
	"reflect"
	"testing"
)

// ─── User.IsEmailVerified ────────────────────────────────────────────────────

func TestIsEmailVerified_NilPointer(t *testing.T) {
	u := &User{}
	if u.IsEmailVerified() {
		t.Fatal("expected false when EmailVerified is nil")
	}
}

func TestIsEmailVerified_False(t *testing.T) {
	v := false
	u := &User{EmailVerified: &v}
	if u.IsEmailVerified() {
		t.Fatal("expected false when EmailVerified is &false")
	}
}

func TestIsEmailVerified_True(t *testing.T) {
	v := true
	u := &User{EmailVerified: &v}
	if !u.IsEmailVerified() {
		t.Fatal("expected true when EmailVerified is &true")
	}
}

// ─── User struct tag doğrulamaları ──────────────────────────────────────────

func TestUser_PasswordHiddenFromJSON(t *testing.T) {
	f, ok := reflect.TypeOf(User{}).FieldByName("Password")
	if !ok {
		t.Fatal("User has no Password field")
	}
	if tag := f.Tag.Get("json"); tag != "-" {
		t.Fatalf("expected Password json tag to be \"-\", got %q", tag)
	}
}

func TestUser_EmailUniqueIndexTagSet(t *testing.T) {
	f, ok := reflect.TypeOf(User{}).FieldByName("Email")
	if !ok {
		t.Fatal("User has no Email field")
	}
	if gormTag := f.Tag.Get("gorm"); gormTag == "" {
		t.Fatal("Email field has no gorm tag")
	}
}

// ─── RefreshToken alanları ───────────────────────────────────────────────────

func TestRefreshToken_HasRequiredFields(t *testing.T) {
	typ := reflect.TypeOf(RefreshToken{})
	required := []string{"UserID", "TokenID", "TokenHash", "TokenFingerprint", "ExpiresAt", "Revoked"}
	for _, name := range required {
		if _, ok := typ.FieldByName(name); !ok {
			t.Errorf("RefreshToken missing required field: %s", name)
		}
	}
}
