package service

import (
	"context"

	"bsm/full/module/ec/mall/internal/server"
	pb "bsm/full/module/ec/mall/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.RegisterAdsHandlerServer(ctx, options.Gateway, server.NewAdsServer()); err != nil {
		return err
	}
	if err := pb.RegisterCategoryHandlerServer(ctx, options.Gateway, server.NewCategoryServer()); err != nil {
		return err
	}
	if err := pb.RegisterFreightHandlerServer(ctx, options.Gateway, server.NewFreightServer()); err != nil {
		return err
	}
	if err := pb.RegisterNoticeHandlerServer(ctx, options.Gateway, server.NewNoticeServer()); err != nil {
		return err
	}
	if err := pb.RegisterProductHandlerServer(ctx, options.Gateway, server.NewProductServer()); err != nil {
		return err
	}
	if err := pb.RegisterStaffHandlerServer(ctx, options.Gateway, server.NewStaffServer()); err != nil {
		return err
	}
	if err := pb.RegisterStoreHandlerServer(ctx, options.Gateway, server.NewStoreServer()); err != nil {
		return err
	}
	return nil
}
