package mocks

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

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

type MockFileKeys struct {
	GetResponse      *common.FileKey
	GetMultiResponse []common.FileKey
	DBMockHelper
}

func (fk *MockFileKeys) Delete(fileID string) (orm.Result, error) {
	if fileID == "" {
		return nil, &validator.FieldError{
			ErrorMsg: "FileID required",
		}
	}

	return fk.ORMResponse, fk.Error
}

func (fk *MockFileKeys) Insert(filekey common.FileKey) (orm.Result, error) {
	err := validator.ValidateStruct(filekey)

	if err != nil {
		return nil, err
	}

	return fk.ORMResponse, fk.Error
}

func (fk *MockFileKeys) Get(fileID string) (*common.FileKey, error) {
	if fileID == "" {
		return nil, &validator.FieldError{
			ErrorMsg: "FileID required",
		}
	}

	return fk.GetResponse, fk.Error
}

func (fk *MockFileKeys) GetMulti(fileIDs []string) ([]common.FileKey, error) {
	return fk.GetMultiResponse, fk.Error
}
