package messageapi

import (
	"net/http"

	"hyapp/services/gateway-service/internal/client"
	"hyapp/services/gateway-service/internal/transport/http/httproutes"
)

// Handler owns message inbox endpoints and safe profile batches used by Tencent IM conversation UI.
// Private chat delivery remains Tencent IM owned; these handlers only expose backend-owned system inbox facts.
type Handler struct {
	messageClient      client.MessageInboxClient
	actionClient       client.MessageActionConfirmClient
	userProfileClient  client.UserProfileClient
	effectiveVIPClient client.UserEffectiveVIPClient
}

type Config struct {
	MessageClient      client.MessageInboxClient
	ActionClient       client.MessageActionConfirmClient
	UserProfileClient  client.UserProfileClient
	EffectiveVIPClient client.UserEffectiveVIPClient
}

func New(config Config) *Handler {
	return &Handler{
		messageClient:      config.MessageClient,
		actionClient:       config.ActionClient,
		userProfileClient:  config.UserProfileClient,
		effectiveVIPClient: config.EffectiveVIPClient,
	}
}

func (h *Handler) MessageHandlers() httproutes.MessageHandlers {
	return httproutes.MessageHandlers{
		ListMessageTabs:          h.listMessageTabs,
		MarkInboxSectionRead:     h.markInboxSectionRead,
		MarkInboxMessageReadPath: h.markInboxMessageReadByPath,
		DeleteInboxMessagePath:   h.deleteInboxMessageByPath,
		ListInboxMessages:        h.listInboxMessages,
		AcceptActionConfirm:      h.acceptActionConfirm,
		RejectActionConfirm:      h.rejectActionConfirm,
		BatchActionConfirmStatus: h.batchActionConfirmStatus,
		ListActionConfirms:       h.listActionConfirms,
	}
}

func (h *Handler) BatchUserProfiles(writer http.ResponseWriter, request *http.Request) {
	h.batchUserProfiles(writer, request)
}
