package mocks

import (
	"github.com/go-pg/pg/v10/orm"

	"github.com/fiskerinc/cloud-services/pkg/common"
	"github.com/fiskerinc/cloud-services/pkg/validator"
)

// MockDrivers
type MockDrivers struct {
	SelectResponse     []common.Driver
	SelectListResponse []common.Driver
	DBMockHelper
}

func (d *MockDrivers) Select(filter *common.Driver) ([]common.Driver, error) {
	d.LastFilter = filter

	return d.SelectResponse, d.Error
}

func (d *MockDrivers) SelectOrInsert(driver *common.Driver) (bool, error) {
	return d.SelectOrInsertResult, d.Error
}

func (d *MockDrivers) Delete(driver *common.Driver) (orm.Result, error) {
	return d.ORMResponse, d.Error
}

func (d *MockDrivers) Insert(driver *common.Driver) (orm.Result, error) {
	err := validator.ValidateStruct(driver)
	if err != nil {
		return nil, err
	}

	return d.ORMResponse, d.Error
}

func (d *MockDrivers) Load(driver *common.Driver) error {
	if d.Error != nil {
		return d.Error
	}

	return nil
}

func (d *MockDrivers) SetListResp(list interface{}) {
	if list != nil {
		d.SelectListResponse = list.([]common.Driver)
	} else {
		d.SelectListResponse = nil
	}
}
