package validations

import (
	"fmt"
)

// NewError generate a new error for a model's field
func NewError(resource interface{}, column, err string) error {
	return &Error{Resource: resource, Column: column, Message: err}
}

// Error is a validation error struct that hold model, column and error message
type Error struct {
	Resource interface{}
	Column   string
	Message  string
}

// Label is a label including model type, primary key and column name
//func (err Error) Label() string {
//	scope := gorm.Scope{Value: err.Resource}
//	return fmt.Sprintf("%v_%v_%v", scope.GetModelStruct().ModelType.Name(), scope.PrimaryKeyValue(), err.Column)
//}

// Error show error message
func (err Error) Error() string {
	return fmt.Sprintf("%v", err.Message)
}
