package sresponse

import (
	"net/http"

	"github.com/tech/sendico/pkg/api/http/response"
	"github.com/tech/sendico/pkg/mlogger"
	"github.com/tech/sendico/pkg/model"
)

type callbackWriteResponse struct {
	AccessToken            TokenData        `json:"accessToken"`
	Callbacks              []model.Callback `json:"callbacks"`
	GeneratedSigningSecret string           `json:"generatedSigningSecret,omitempty"`
}

func Callback(
	logger mlogger.Logger,
	callback *model.Callback,
	accessToken *TokenData,
	generatedSecret string,
	created bool,
) http.HandlerFunc {
	resp := callbackWriteResponse{
		AccessToken:            *accessToken,
		Callbacks:              []model.Callback{*callback},
		GeneratedSigningSecret: generatedSecret,
	}
	if created {
		return response.Created(logger, resp)
	}
	return response.Ok(logger, resp)
}
