package service

import (
	"context"

	"bsm/full/module/base/passport/internal/config"
	"bsm/full/module/base/passport/internal/server"
	pb "bsm/full/module/base/passport/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.RegisterAccountHandlerServer(ctx, options.Gateway, server.NewAccountServer()); err != nil {
		return err
	}
	if err := pb.RegisterForgetHandlerServer(ctx, options.Gateway, server.NewForgetServer()); err != nil {
		return err
	}
	if err := pb.RegisterLoginHandlerServer(ctx, options.Gateway, server.NewLoginServer()); err != nil {
		return err
	}
	if err := pb.RegisterRegisterHandlerServer(ctx, options.Gateway, server.NewRegisterServer()); err != nil {
		return err
	}
	if err := pb.RegisterVerifyHandlerServer(ctx, options.Gateway, server.NewVerifyServer()); err != nil {
		return err
	}
	return nil
}
