package contract

type Response struct {
	Success bool             `json:"success"`
	Data    interface{}      `json:"data"`
	Errors  []*ResponseError `json:"errors"`
}

func (r *Response) GetSuccess() bool {
	return r.Success
}

func (r *Response) GetData() interface{} {
	return r.Data
}

func (r *Response) GetErrors() []*ResponseError {
	return r.Errors
}

func BuildSuccessResponse(data interface{}) *Response {
	return &Response{
		Success: true,
		Data:    data,
		Errors:  []*ResponseError(nil),
	}
}

func BuildErrorResponse(errorList []*ResponseError) *Response {
	return &Response{
		Success: false,
		Data:    nil,
		Errors:  errorList,
	}
}

func (r *Response) HasErrors() bool {
	return r.GetErrors() != nil && len(r.GetErrors()) > 0
}
