package service

import (
	"context"

	"bsm/full/module/finance/wallet/internal/config"
	"bsm/full/module/finance/wallet/internal/server"
	pb "bsm/full/module/finance/wallet/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.RegisterAlipayHandlerServer(ctx, options.Gateway, server.NewAlipayServer()); err != nil {
		return err
	}
	if err := pb.RegisterPaymentHandlerServer(ctx, options.Gateway, server.NewPaymentServer()); err != nil {
		return err
	}
	if err := pb.RegisterBasicHandlerServer(ctx, options.Gateway, server.NewBasicServer()); err != nil {
		return err
	}
	if err := pb.RegisterWechatHandlerServer(ctx, options.Gateway, server.NewWechatServer()); err != nil {
		return err
	}
	return nil
}
