package service

import (
	"context"

	"bsm/full/module/ec/order/internal/server"
	pb "bsm/full/module/ec/order/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.RegisterCartHandlerServer(ctx, options.Gateway, server.NewCartServer()); err != nil {
		return err
	}
	if err := pb.RegisterCouponHandlerServer(ctx, options.Gateway, server.NewCouponServer()); err != nil {
		return err
	}
	if err := pb.RegisterMgtHandlerServer(ctx, options.Gateway, server.NewMgtServer()); err != nil {
		return err
	}
	if err := pb.RegisterSummaryHandlerServer(ctx, options.Gateway, server.NewSummaryServer()); err != nil {
		return err
	}
	return nil
}
