// Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT.

package mocks

//go:generate minimock -i learngo-pockets/habits/internal/habit.habitFinder -o habit_finder_mock.go -n HabitFinderMock -p mocks

import (
	"context"
	mm_habit "learngo-pockets/habits/internal/habit"
	"sync"
	mm_atomic "sync/atomic"
	mm_time "time"

	"github.com/gojuno/minimock/v3"
)

// HabitFinderMock implements habit.habitFinder
type HabitFinderMock struct {
	t          minimock.Tester
	finishOnce sync.Once

	funcFind          func(ctx context.Context, id mm_habit.ID) (h1 mm_habit.Habit, err error)
	inspectFuncFind   func(ctx context.Context, id mm_habit.ID)
	afterFindCounter  uint64
	beforeFindCounter uint64
	FindMock          mHabitFinderMockFind
}

// NewHabitFinderMock returns a mock for habit.habitFinder
func NewHabitFinderMock(t minimock.Tester) *HabitFinderMock {
	m := &HabitFinderMock{t: t}

	if controller, ok := t.(minimock.MockController); ok {
		controller.RegisterMocker(m)
	}

	m.FindMock = mHabitFinderMockFind{mock: m}
	m.FindMock.callArgs = []*HabitFinderMockFindParams{}

	return m
}

type mHabitFinderMockFind struct {
	mock               *HabitFinderMock
	defaultExpectation *HabitFinderMockFindExpectation
	expectations       []*HabitFinderMockFindExpectation

	callArgs []*HabitFinderMockFindParams
	mutex    sync.RWMutex
}

// HabitFinderMockFindExpectation specifies expectation struct of the habitFinder.Find
type HabitFinderMockFindExpectation struct {
	mock    *HabitFinderMock
	params  *HabitFinderMockFindParams
	results *HabitFinderMockFindResults
	Counter uint64
}

// HabitFinderMockFindParams contains parameters of the habitFinder.Find
type HabitFinderMockFindParams struct {
	ctx context.Context
	id  mm_habit.ID
}

// HabitFinderMockFindResults contains results of the habitFinder.Find
type HabitFinderMockFindResults struct {
	h1  mm_habit.Habit
	err error
}

// Expect sets up expected params for habitFinder.Find
func (mmFind *mHabitFinderMockFind) Expect(ctx context.Context, id mm_habit.ID) *mHabitFinderMockFind {
	if mmFind.mock.funcFind != nil {
		mmFind.mock.t.Fatalf("HabitFinderMock.Find mock is already set by Set")
	}

	if mmFind.defaultExpectation == nil {
		mmFind.defaultExpectation = &HabitFinderMockFindExpectation{}
	}

	mmFind.defaultExpectation.params = &HabitFinderMockFindParams{ctx, id}
	for _, e := range mmFind.expectations {
		if minimock.Equal(e.params, mmFind.defaultExpectation.params) {
			mmFind.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmFind.defaultExpectation.params)
		}
	}

	return mmFind
}

// Inspect accepts an inspector function that has same arguments as the habitFinder.Find
func (mmFind *mHabitFinderMockFind) Inspect(f func(ctx context.Context, id mm_habit.ID)) *mHabitFinderMockFind {
	if mmFind.mock.inspectFuncFind != nil {
		mmFind.mock.t.Fatalf("Inspect function is already set for HabitFinderMock.Find")
	}

	mmFind.mock.inspectFuncFind = f

	return mmFind
}

// Return sets up results that will be returned by habitFinder.Find
func (mmFind *mHabitFinderMockFind) Return(h1 mm_habit.Habit, err error) *HabitFinderMock {
	if mmFind.mock.funcFind != nil {
		mmFind.mock.t.Fatalf("HabitFinderMock.Find mock is already set by Set")
	}

	if mmFind.defaultExpectation == nil {
		mmFind.defaultExpectation = &HabitFinderMockFindExpectation{mock: mmFind.mock}
	}
	mmFind.defaultExpectation.results = &HabitFinderMockFindResults{h1, err}
	return mmFind.mock
}

// Set uses given function f to mock the habitFinder.Find method
func (mmFind *mHabitFinderMockFind) Set(f func(ctx context.Context, id mm_habit.ID) (h1 mm_habit.Habit, err error)) *HabitFinderMock {
	if mmFind.defaultExpectation != nil {
		mmFind.mock.t.Fatalf("Default expectation is already set for the habitFinder.Find method")
	}

	if len(mmFind.expectations) > 0 {
		mmFind.mock.t.Fatalf("Some expectations are already set for the habitFinder.Find method")
	}

	mmFind.mock.funcFind = f
	return mmFind.mock
}

// When sets expectation for the habitFinder.Find which will trigger the result defined by the following
// Then helper
func (mmFind *mHabitFinderMockFind) When(ctx context.Context, id mm_habit.ID) *HabitFinderMockFindExpectation {
	if mmFind.mock.funcFind != nil {
		mmFind.mock.t.Fatalf("HabitFinderMock.Find mock is already set by Set")
	}

	expectation := &HabitFinderMockFindExpectation{
		mock:   mmFind.mock,
		params: &HabitFinderMockFindParams{ctx, id},
	}
	mmFind.expectations = append(mmFind.expectations, expectation)
	return expectation
}

// Then sets up habitFinder.Find return parameters for the expectation previously defined by the When method
func (e *HabitFinderMockFindExpectation) Then(h1 mm_habit.Habit, err error) *HabitFinderMock {
	e.results = &HabitFinderMockFindResults{h1, err}
	return e.mock
}

// Find implements habit.habitFinder
func (mmFind *HabitFinderMock) Find(ctx context.Context, id mm_habit.ID) (h1 mm_habit.Habit, err error) {
	mm_atomic.AddUint64(&mmFind.beforeFindCounter, 1)
	defer mm_atomic.AddUint64(&mmFind.afterFindCounter, 1)

	if mmFind.inspectFuncFind != nil {
		mmFind.inspectFuncFind(ctx, id)
	}

	mm_params := HabitFinderMockFindParams{ctx, id}

	// Record call args
	mmFind.FindMock.mutex.Lock()
	mmFind.FindMock.callArgs = append(mmFind.FindMock.callArgs, &mm_params)
	mmFind.FindMock.mutex.Unlock()

	for _, e := range mmFind.FindMock.expectations {
		if minimock.Equal(*e.params, mm_params) {
			mm_atomic.AddUint64(&e.Counter, 1)
			return e.results.h1, e.results.err
		}
	}

	if mmFind.FindMock.defaultExpectation != nil {
		mm_atomic.AddUint64(&mmFind.FindMock.defaultExpectation.Counter, 1)
		mm_want := mmFind.FindMock.defaultExpectation.params
		mm_got := HabitFinderMockFindParams{ctx, id}
		if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
			mmFind.t.Errorf("HabitFinderMock.Find got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
		}

		mm_results := mmFind.FindMock.defaultExpectation.results
		if mm_results == nil {
			mmFind.t.Fatal("No results are set for the HabitFinderMock.Find")
		}
		return (*mm_results).h1, (*mm_results).err
	}
	if mmFind.funcFind != nil {
		return mmFind.funcFind(ctx, id)
	}
	mmFind.t.Fatalf("Unexpected call to HabitFinderMock.Find. %v %v", ctx, id)
	return
}

// FindAfterCounter returns a count of finished HabitFinderMock.Find invocations
func (mmFind *HabitFinderMock) FindAfterCounter() uint64 {
	return mm_atomic.LoadUint64(&mmFind.afterFindCounter)
}

// FindBeforeCounter returns a count of HabitFinderMock.Find invocations
func (mmFind *HabitFinderMock) FindBeforeCounter() uint64 {
	return mm_atomic.LoadUint64(&mmFind.beforeFindCounter)
}

// Calls returns a list of arguments used in each call to HabitFinderMock.Find.
// The list is in the same order as the calls were made (i.e. recent calls have a higher index)
func (mmFind *mHabitFinderMockFind) Calls() []*HabitFinderMockFindParams {
	mmFind.mutex.RLock()

	argCopy := make([]*HabitFinderMockFindParams, len(mmFind.callArgs))
	copy(argCopy, mmFind.callArgs)

	mmFind.mutex.RUnlock()

	return argCopy
}

// MinimockFindDone returns true if the count of the Find invocations corresponds
// the number of defined expectations
func (m *HabitFinderMock) MinimockFindDone() bool {
	for _, e := range m.FindMock.expectations {
		if mm_atomic.LoadUint64(&e.Counter) < 1 {
			return false
		}
	}

	// if default expectation was set then invocations count should be greater than zero
	if m.FindMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterFindCounter) < 1 {
		return false
	}
	// if func was set then invocations count should be greater than zero
	if m.funcFind != nil && mm_atomic.LoadUint64(&m.afterFindCounter) < 1 {
		return false
	}
	return true
}

// MinimockFindInspect logs each unmet expectation
func (m *HabitFinderMock) MinimockFindInspect() {
	for _, e := range m.FindMock.expectations {
		if mm_atomic.LoadUint64(&e.Counter) < 1 {
			m.t.Errorf("Expected call to HabitFinderMock.Find with params: %#v", *e.params)
		}
	}

	// if default expectation was set then invocations count should be greater than zero
	if m.FindMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterFindCounter) < 1 {
		if m.FindMock.defaultExpectation.params == nil {
			m.t.Error("Expected call to HabitFinderMock.Find")
		} else {
			m.t.Errorf("Expected call to HabitFinderMock.Find with params: %#v", *m.FindMock.defaultExpectation.params)
		}
	}
	// if func was set then invocations count should be greater than zero
	if m.funcFind != nil && mm_atomic.LoadUint64(&m.afterFindCounter) < 1 {
		m.t.Error("Expected call to HabitFinderMock.Find")
	}
}

// MinimockFinish checks that all mocked methods have been called the expected number of times
func (m *HabitFinderMock) MinimockFinish() {
	m.finishOnce.Do(func() {
		if !m.minimockDone() {
			m.MinimockFindInspect()
			m.t.FailNow()
		}
	})
}

// MinimockWait waits for all mocked methods to be called the expected number of times
func (m *HabitFinderMock) MinimockWait(timeout mm_time.Duration) {
	timeoutCh := mm_time.After(timeout)
	for {
		if m.minimockDone() {
			return
		}
		select {
		case <-timeoutCh:
			m.MinimockFinish()
			return
		case <-mm_time.After(10 * mm_time.Millisecond):
		}
	}
}

func (m *HabitFinderMock) minimockDone() bool {
	done := true
	return done &&
		m.MinimockFindDone()
}
