package error

const InvalidParameter = 400
const ActionForbidden = 401
const NotFound = 404
const InternalError = 500

type apiErrorParameter struct {
	ErrorType string `json:"type"`
	Parameter string `json:"parameter"`
	Message   string `json:"message"`
}

type apiError struct {
	ErrorType string `json:"type"`
	Message   string `json:"message"`
}

type Errors struct {
	Errors []interface{} `json:"errors"`
}

func (err *Errors) InvalidParameter(parameter string, message string) {
	var e = apiErrorParameter{
		"invalid_parameter",
		parameter,
		message,
	}

	err.Errors = append(err.Errors, e)
}

func (err *Errors) ActionForbidden(message string) {
	var e = apiError{
		"action_forbidden",
		message,
	}

	err.Errors = append(err.Errors, e)
}

func (err *Errors) InternalError(message string) {
	var e = apiError{
		"internal_error",
		message,
	}

	err.Errors = append(err.Errors, e)
}

func (err *Errors) NotFound(message string) {
	var e = apiError{
		"not_found",
		message,
	}

	err.Errors = append(err.Errors, e)
}

func (err *Errors) Has() bool {
	if len(err.Errors) > 0 {
		return true
	}

	return false
}
