package api

import (
	"fmt"

	"github.com/ngaut/log"
)

const (
	statusOK             = 200
	statusWrongParameter = 1
	statusNotFound       = 2
	statusOtherError     = 3
)

// Response represents message that returns to client
type Response struct {
	Message string      `json:"message"`
	Code    int         `json:"code"`
	Data    interface{} `json:"data"`
}

func successResponse(data interface{}) *Response {
	return &Response{
		Code: statusOK,
		Data: data,
	}
}

func notFoundResponsef(format string, args ...interface{}) *Response {
	format = format + " not found"
	return &Response{
		Code:    statusNotFound,
		Message: fmt.Sprintf(format, args...),
	}
}

func errResponsef(format string, args ...interface{}) *Response {
	errMsg := fmt.Sprintf(format, args...)
	log.Error(errMsg)
	return &Response{
		Code:    statusOtherError,
		Message: errMsg,
	}
}
