package api

import (
	"testing"
	"time"

	"code.secondbit.org/uuid.hg"
)

var datastores = []Datastore{NewMemstore()}

func compareCollections(expectation, result Collection) (field string, expected, got interface{}) {
	if !expectation.ID.Equal(result.ID) {
		return "ID", expectation.ID, result.ID
	}
	if expectation.Name != result.Name {
		return "name", expectation.Name, result.Name
	}
	if !expectation.Owner.Equal(result.Owner) {
		return "owner", expectation.Owner, result.Owner
	}
	if !expectation.Created.Equal(result.Created) {
		return "created", expectation.Created, result.Created
	}
	return "", nil, nil
}

func TestCreateCollection(t *testing.T) {
	for pos, datastore := range datastores {
		expectation := Collection{
			ID:      uuid.NewID(),
			Name:    "Test Collection",
			Owner:   uuid.NewID(),
			Created: time.Now(),
		}
		err := datastore.CreateCollection(expectation)
		if err != nil {
			t.Errorf("Error creating collection in datastore %d: %s\n", pos, err)
		}
		result, err := datastore.GetCollectionByID(expectation.ID)
		if err != nil {
			t.Errorf("Error retrieving collection in datastore %d: %s\n", pos, err)
		}
		field, exp, got := compareCollections(expectation, result)
		if field != "" {
			t.Errorf("Collection did not meet expectations for datastore %d. Expected %v for %s, got %v.", pos, exp, field, got)
		}
	}
}

func TestUpdateCollection(t *testing.T) {
}

func TestUpdateCollectionCollectionNotFound(t *testing.T) {
}

func TestGetCollectionByDomain(t *testing.T) {
}

func TestGetCollectionByDomainCollectionNotFound(t *testing.T) {
}

func TestGetCollectionByID(t *testing.T) {
}

func TestGetCollectionByIDCollectionNotFound(t *testing.T) {
}

func TestGetCollectionsByUser(t *testing.T) {
}

func TestGetCollectionsByUserNoCollections(t *testing.T) {
}

func TestAddDomainToCollection(t *testing.T) {
}

func TestAddDomainToCollectionDomainAlreadyExists(t *testing.T) {
}

func TestAddDomainToCollectionCollectionNotFound(t *testing.T) {
}

func TestRemoveDomainFromCollection(t *testing.T) {
}

func TestRemoveDomainFromCollectionDomainNotFound(t *testing.T) {
}

func TestGetDomainsByCollection(t *testing.T) {
}

func TestGetDomainsByCollectionNoResults(t *testing.T) {
}

func TestDeleteCollection(t *testing.T) {
}

func TestDeleteCollectionCollectionNotFound(t *testing.T) {
}

func TestGetItemsByCollectionDomain(t *testing.T) {
}

func TestGetItemsByCollectionDomainCollectionNotFound(t *testing.T) {
}

func TestGetItemsByCollectionDomainNoResults(t *testing.T) {
}

func TestGetItemsByCollectionID(t *testing.T) {
}

func TestGetItemsByCollectionIDCollectionNotFound(t *testing.T) {
}

func TestGetItemsByCollectionIDNoResults(t *testing.T) {
}

func TestAddItemToCollection(t *testing.T) {
}

func TestAddItemToCollectionCollectionNotFound(t *testing.T) {
}

func TestAddItemToCollectionItemAlreadyExists(t *testing.T) {
}

func TestGetItemByName(t *testing.T) {
}

func TestGetItemByNameCollectionNotFound(t *testing.T) {
}

func TestGetItemByNameItemNotFound(t *testing.T) {
}

func TestDeleteItem(t *testing.T) {
}

func TestDeleteItemItemNotFound(t *testing.T) {
}
