package service

import (
	"context"

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

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

type Config = config.SrvConfig

func Expose(options ExposeOptions) error {
	applyDependencies(options.Dependencies)
	if options.Config != nil {
		config.Spec = *options.Config
	}
	server.New(options.GRPC)

	ctx := context.Background()
	if err := pb.RegisterMailHandlerServer(ctx, options.Gateway, server.NewMailServer()); err != nil {
		return err
	}
	if err := pb.RegisterSmsHandlerServer(ctx, options.Gateway, server.NewSmsServer()); err != nil {
		return err
	}
	return nil
}
