package mqs

import (
	"context"
	"github.com/zeromicro/go-queue/rabbitmq"
	"github.com/zeromicro/go-zero/core/logc"
	"log"
	"microGame/app/mq/cmd/rabbitmq/internal/svc"
)

func InitMq(svcCtx *svc.ServiceContext) error {

	ctx := context.Background()
	admin := svcCtx.RabbitAdmin
	exchangeConf := rabbitmq.ExchangeConf{
		ExchangeName: "poker-bet",
		Type:         "direct",
		Durable:      true,
		AutoDelete:   false,
		Internal:     false,
		NoWait:       false,
	}

	err := admin.DeclareExchange(exchangeConf, nil)
	if err != nil {
		logc.Errorf(ctx, "admin.DeclareExchange rabbitmq %+v\n", err)
	}

	queueConf := rabbitmq.QueueConf{
		Name:       "poker-bet",
		Durable:    true,
		AutoDelete: false,
		Exclusive:  false,
		NoWait:     false,
	}
	err = admin.DeclareQueue(queueConf, nil)
	if err != nil {
		logc.Errorf(ctx, "admin.DeclareQueue rabbitmq %+v\n", err)
	}

	err = admin.Bind("poker-bet", "poker-bet", "poker-bet", false, nil)
	if err != nil {
		log.Fatal(err)
	}
	return err
}
