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 organizationsResponse struct {
	authResponse  `json:",inline"`
	Organizations []model.Organization `json:"organizations"`
}

func Organization(logger mlogger.Logger, organization *model.Organization, accessToken *TokenData) http.HandlerFunc {
	return Organizations(logger, []model.Organization{*organization}, accessToken)
}

func Organizations(logger mlogger.Logger, organizations []model.Organization, accessToken *TokenData) http.HandlerFunc {
	return response.Ok(logger, organizationsResponse{
		Organizations: organizations,
		authResponse:  authResponse{AccessToken: *accessToken},
	})
}

type organizationPublicResponse struct {
	Organizations []model.OrganizationBase `json:"organizations"`
}

func OrganizationPublic(logger mlogger.Logger, organization *model.OrganizationBase) http.HandlerFunc {
	return response.Ok(logger, organizationPublicResponse{
		[]model.OrganizationBase{*organization},
	})
}
