package service

import (
	"context"

	"bsm/full/module/base/cms/internal/server"
	pb "bsm/full/module/base/cms/pb"
	gwRuntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
	"google.golang.org/grpc"
)

type ExposeOptions struct {
	Dependencies
	GRPC    *grpc.Server
	Gateway *gwRuntime.ServeMux
}

func Expose(options ExposeOptions) error {
	applyDependencies(options.Dependencies)
	server.New(options.GRPC)

	ctx := context.Background()
	if err := pb.RegisterCategoryHandlerServer(ctx, options.Gateway, server.NewCategoryServer()); err != nil {
		return err
	}
	if err := pb.RegisterPagesHandlerServer(ctx, options.Gateway, server.NewPagesServer()); err != nil {
		return err
	}
	if err := pb.RegisterPostHandlerServer(ctx, options.Gateway, server.NewPostServer()); err != nil {
		return err
	}
	if err := pb.RegisterSiteHandlerServer(ctx, options.Gateway, server.NewSiteServer()); err != nil {
		return err
	}
	if err := pb.RegisterTagsHandlerServer(ctx, options.Gateway, server.NewTagsServer()); err != nil {
		return err
	}
	return nil
}
