package action

import (
	"pbx-api-gin/internal/app/ami/model"

	"github.com/mitchellh/mapstructure"
)

// QueueStatus 队列信息
func QueueStatus(queue, member string) (queueParams *model.QueueParams, err error) {
	action := map[string]string{
		"Action": "QueueStatus",
	}
	if queue != "" {
		action["Queue"] = queue
	}
	if member != "" {
		action["Member"] = member
	}
	_, events, _ := AminInstance.Send(action)
	for _, event := range events {
		if event.Data["Event"] == "QueueParams" {
			queueParams = &model.QueueParams{Members: make([]*model.QueueMember, 0), Entrys: make([]*model.QueueEntry, 0)}
			mapstructure.Decode(event.Data, queueParams)
			continue
		}
		if event.Data["Event"] == "QueueMember" {
			member := &model.QueueMember{}
			mapstructure.Decode(event.Data, member)
			queueParams.Members = append(queueParams.Members, member)
			continue
		}

		if event.Data["Event"] == "QueueEntry" {
			entry := &model.QueueEntry{}
			mapstructure.Decode(event.Data, entry)
			queueParams.Entrys = append(queueParams.Entrys, entry)
			continue
		}
	}
	//lfshook.NewLogger().Infof("================QueueStatus calls:%v===========", queueParams.Calls)
	return queueParams, nil
}
