package handler

import (
	"context"
	"net/http"

	"git.intra.yksa.space/gsn/predictor/internal/pkg/errcodes"
	api "git.intra.yksa.space/gsn/predictor/pkg/rest"
)

var (
	_ api.Handler = (*Handler)(nil)
)

type Handler struct {
	svc Service
}

func New(svc Service) *Handler {
	return &Handler{
		svc: svc,
	}
}

func (h *Handler) PerformPrediction(ctx context.Context, req api.OptPredictionParameters, params api.PerformPredictionParams) (*api.PredictionResult, error) {
	return nil, errcodes.New(http.StatusNotImplemented, "not implemented", "please wait")
}

func (h *Handler) NewError(ctx context.Context, err error) *api.ErrorStatusCode {
	if errcode, ok := err.(*errcodes.ErrorCode); ok {
		resp := api.Error{
			Message: errcode.Message,
		}

		if errcode.Details != "" {
			resp.Details = api.NewOptString(errcode.Details)
		}

		return &api.ErrorStatusCode{
			StatusCode: errcode.StatusCode,
			Response:   resp,
		}
	}

	return &api.ErrorStatusCode{
		StatusCode: http.StatusInternalServerError,
		Response: api.Error{
			Message: "undefined internal error",
			Details: api.NewOptString(err.Error()),
		},
	}
}
