package callbackapi

import (
	"net/http"
	"time"

	"hyapp/services/gateway-service/internal/client"
)

// TencentIMConfig 是腾讯云 IM 服务端回调校验需要的最小配置。
type TencentIMConfig struct {
	SDKAppID          int64
	AdminIdentifier   string
	CallbackAuthToken string
	GroupIDPrefix     string
}

// TencentRTCConfig 是腾讯云 RTC 服务端回调校验需要的最小配置。
type TencentRTCConfig struct {
	SDKAppID        int64
	CallbackSignKey string
	UserSigTTL      time.Duration
}

// Handler owns external Tencent callback endpoints.
// Tencent callback responses intentionally bypass gateway envelope because Tencent only accepts provider-native shapes.
type Handler struct {
	roomClient        client.RoomClient
	roomGuardClient   client.RoomGuardClient
	userProfileClient client.UserProfileClient
	userHostClient    client.UserHostClient
	tencentIM         TencentIMConfig
	tencentRTC        TencentRTCConfig
}

type Config struct {
	RoomClient        client.RoomClient
	RoomGuardClient   client.RoomGuardClient
	UserProfileClient client.UserProfileClient
	UserHostClient    client.UserHostClient
	TencentIM         TencentIMConfig
	TencentRTC        TencentRTCConfig
}

func New(config Config) *Handler {
	return &Handler{
		roomClient:        config.RoomClient,
		roomGuardClient:   config.RoomGuardClient,
		userProfileClient: config.UserProfileClient,
		userHostClient:    config.UserHostClient,
		tencentIM:         config.TencentIM,
		tencentRTC:        config.TencentRTC,
	}
}

func (h *Handler) HandleTencentIMCallback(writer http.ResponseWriter, request *http.Request) {
	h.handleTencentIMCallback(writer, request)
}

func (h *Handler) HandleTencentRTCCallback(writer http.ResponseWriter, request *http.Request) {
	h.handleTencentRTCCallback(writer, request)
}
