package domain

import (
	"context"

	"git.vdhsn.com/barretthousen/barretthousen/src/auth/internal/data"
	"go.uber.org/dig"
)

var ioc dig.Container

func SetupTest() {
	ioc = *dig.New()

	if err := ioc.Provide(func() (Storage, *MockStorage) {
		ms := &MockStorage{}
		return ms, ms
	}); err != nil {
		panic(err)
	}
}

// Must panics is err is not nil
func Must(err error) {
	if err != nil {
		panic(err)
	}
}

type MockStorage struct {
	RegisterAccountFunc func(context.Context, data.RegisterAccountInput) (int, error)
	GetAccountFunc      func(context.Context, data.GetAccountInput) (data.AccountResult, error)
	CreateSessionFunc   func(context.Context, data.CreateSessionInput) (data.Session, error)
}

// CreateSession implements Storage.
func (m *MockStorage) CreateSession(ctx context.Context, in data.CreateSessionInput) (data.Session, error) {
	if m.CreateSessionFunc == nil {
		panic("CreateSessionFunc is unset")
	}
	return m.CreateSessionFunc(ctx, in)
}

// GetAccount implements Storage.
func (m *MockStorage) GetAccount(ctx context.Context, in data.GetAccountInput) (data.AccountResult, error) {
	if m.GetAccountFunc == nil {
		panic("GetAccountFunc is unset")
	}

	return m.GetAccountFunc(ctx, in)
}

// GetAccountBySession implements Storage.
func (m *MockStorage) GetAccountBySession(ctx context.Context, in int) (data.AccountResult, error) {
	panic("GetAccountBySession not implemented")
}

// RegisterAccount implements Storage.
func (m *MockStorage) RegisterAccount(ctx context.Context, in data.RegisterAccountInput) (int, error) {
	if m.RegisterAccountFunc == nil {
		panic("RegisterAccountFunc is unset")
	}

	return m.RegisterAccountFunc(ctx, in)
}

// VerifyAccount implements Storage.
func (*MockStorage) VerifyAccount(context.Context, data.VerifyAccountInput) error {
	panic("unimplemented")
}
