package mocks

import (
	"github.com/fiskerinc/cloud-services/pkg/common"
	"github.com/fiskerinc/cloud-services/pkg/db/queries"

	"github.com/go-pg/pg/v10/orm"
)

// CarUpdate query methods
type MockSupplierAccounts struct {
	DBMockHelper
	MockListResponse    []common.SupplierAccount
	MockSupplierAccount *common.SupplierAccount
}

func (c *MockSupplierAccounts) Count(account *common.SupplierAccount) (int, error) {
	return len(c.MockListResponse), c.Error
}

func (c *MockSupplierAccounts) Delete(account *common.SupplierAccount) (orm.Result, error) {
	c.LastFilter = account
	return c.ORMResponse, c.Error
}

func (c *MockSupplierAccounts) Insert(account *common.SupplierAccount) (orm.Result, error) {
	c.LastFilter = account
	return c.ORMResponse, c.Error
}

func (c *MockSupplierAccounts) Load(account *common.SupplierAccount) error {
	c.LastFilter = account

	if c.MockSupplierAccount != nil {
		account.ECUs = c.MockSupplierAccount.ECUs
		account.ActivatedAt = c.MockSupplierAccount.ActivatedAt
	}

	return c.Error
}

func (c *MockSupplierAccounts) Select(account *common.SupplierAccount, paging *queries.PageQueryOptions) ([]common.SupplierAccount, error) {
	c.LastFilter = account
	c.LastPaging = paging

	return c.MockListResponse, c.Error
}

func (c *MockSupplierAccounts) Update(account *common.SupplierAccount) (orm.Result, error) {
	c.LastFilter = account
	return c.ORMResponse, c.Error
}

func (c *MockSupplierAccounts) Approve(email string) (orm.Result, error) {
	return c.ORMResponse, c.Error
}

func (c *MockSupplierAccounts) UpdateTimestamp(email string, activity queries.SupplierTimestamp) (orm.Result, error) {
	return c.ORMResponse, c.Error
}

func (c *MockSupplierAccounts) SetListResp(list interface{}) {
	if list != nil {
		c.MockListResponse = list.([]common.SupplierAccount)
	}
}

func (c *MockSupplierAccounts) SetLoadResp(item interface{}) {
	// fmt.Printf("override SetLoadResp() in %s\n", reflect.TypeOf(item))
}
