package migration

import "testing"

func TestGooglePersonDeletedMetadata(t *testing.T) {
	person := googlePerson{
		ResourceName: "people/abc",
		Metadata:     &struct{ Deleted bool `json:"deleted"` }{Deleted: true},
	}
	if person.Metadata == nil || !person.Metadata.Deleted {
		t.Fatal("expected deleted metadata")
	}
}

func TestGraphContactRemoved(t *testing.T) {
	removed := struct {
		Reason string `json:"reason"`
	}{Reason: "deleted"}
	item := graphContact{ID: "c1", Removed: &removed}
	if item.Removed == nil {
		t.Fatal("expected removed marker")
	}
}

func TestGooglePersonToContact(t *testing.T) {
	person := googlePerson{
		ResourceName: "people/abc",
		Names:        []struct{ DisplayName string `json:"displayName"` }{{DisplayName: "Alice"}},
		EmailAddresses: []struct {
			Value string `json:"value"`
		}{{Value: "Alice@Example.COM"}},
	}
	contact := googlePersonToContact("people/abc", person)
	if contact.FullName != "Alice" || contact.Email != "alice@example.com" {
		t.Fatalf("contact: %#v", contact)
	}
}

func TestGraphContactToNC(t *testing.T) {
	item := graphContact{
		ID:          "c1",
		GivenName:   "Bob",
		Surname:     "Smith",
		MobilePhone: "+33123456789",
		CompanyName: "Acme",
		EmailAddresses: []struct {
			Address string `json:"address"`
		}{{Address: "bob@example.com"}},
	}
	contact := graphContactToNC("c1", item)
	if contact.FullName != "Bob Smith" || contact.Org != "Acme" {
		t.Fatalf("contact: %#v", contact)
	}
}
