1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 
<?php

namespace SAREhub\Client\Amqp;


use PhpAmqpLib\Wire\AMQPTable;

class AmqpConsumerOptions implements \JsonSerializable
{
    /**
     * @var string
     */
    private $queueName = '';

    /**
     * @var string
     */
    private $tag = '';

    /**
     * @var int
     */
    private $priority = 0;

    /**
     * @var bool
     */
    private $autoAck = false;

    /**
     * @var bool
     */
    private $exclusive = false;

    public static function newInstance(): AmqpConsumerOptions
    {
        return new self();
    }

    public function setQueueName(string $queueName): AmqpConsumerOptions
    {
        $this->queueName = $queueName;
        return $this;
    }

    public function setTag(string $tag): AmqpConsumerOptions
    {
        $this->tag = $tag;
        return $this;
    }

    public function setPriority(int $priority): AmqpConsumerOptions
    {
        $this->priority = $priority;
        return $this;
    }

    public function setAckMode(): AmqpConsumerOptions
    {
        $this->autoAck = false;
        return $this;
    }

    public function setAutoAckMode(): AmqpConsumerOptions
    {
        $this->autoAck = true;
        return $this;
    }

    public function setExclusive(bool $exclusive): AmqpConsumerOptions
    {
        $this->exclusive = $exclusive;
        return $this;
    }

    public function getQueueName(): string
    {
        return $this->queueName;
    }

    public function getTag(): string
    {
        return $this->tag;
    }

    public function getPriority(): int
    {
        return $this->priority;
    }

    public function isAutoAckMode(): bool
    {
        return $this->autoAck;
    }

    public function isAckMode(): bool
    {
        return !$this->autoAck;
    }

    public function isExclusive(): bool
    {
        return $this->exclusive;
    }

    public function getConsumeArguments(): AMQPTable
    {
        $args = [];
        if ($this->getPriority() > 0) {
            $args["x-priority"] = $this->getPriority();
        }
        return new AMQPTable($args);
    }

    public function jsonSerialize()
    {
        return [
            "queueName" => $this->getQueueName(),
            "tag" => $this->getTag(),
            "priority" => $this->getPriority(),
            "isAutoAck" => $this->isAutoAckMode(),
            "isExclusive" => $this->isExclusive()
        ];
    }
}