<?php

namespace Fifa\ConnectServiceBus\Sdk;

use Fifa\ConnectServiceBus\Sdk\Exception\AuthenticationException;
use Fifa\ConnectServiceBus\Sdk\Exception\DecryptionException;
use Fifa\ConnectServiceBus\Sdk\Exception\FifaConnectServiceBusSdkException;
use Fifa\ConnectServiceBus\Sdk\Exception\InvalidClientDataException;
use Fifa\ConnectServiceBus\Sdk\Exception\MessageNotFoundException;
use Fifa\ConnectServiceBus\Sdk\Exception\QueueNotFoundException;
use Fifa\ConnectServiceBus\Sdk\Exception\TooManyRequestsException;
use Fifa\ConnectServiceBus\Sdk\Exception\UnauthorizedException;
use Fifa\ConnectServiceBus\Sdk\Message\Message;

/**
 * Interface FifaConnectServiceBusClientInterface
 * @package Fifa\ConnectServiceBus\Sdk
 */
interface FifaConnectServiceBusClientInterface
{
    /**
     * @var int
     */
    const HTTP_CODE_CONFLICT = 409;

    /**
     * @var int
     */
    const HTTP_CODE_NOT_FOUND = 404;

    /**
     * @var int
     */
    const HTTP_CODE_OK = 200;

    /**
     * @var int
     */
    const HTTP_CODE_CREATED = 201;

    /**
     * @var int
     */
    const HTTP_CODE_NO_CONTENT = 204;

    /**
     * Sends a message to a specified recipient via Message Bus.
     *
     * @param string $recipient
     * @param Message $message
     *
     * @throws InvalidClientDataException
     * @throws QueueNotFoundException
     * @throws FifaConnectServiceBusSdkException
     * @throws UnauthorizedException
     * @throws AuthenticationException
     * @throws TooManyRequestsException
     */
    public function send(string $recipient, Message $message);

    /**
     * Gets and locks a message without deleting it from the queue. If message is not deleted within configured time it's automatically unlocked and visible for other recipients.
     *
     * @param int $timeout
     * @return Message|null
     *
     * @throws QueueNotFoundException
     * @throws InvalidClientDataException
     * @throws FifaConnectServiceBusSdkException
     * @throws UnauthorizedException
     * @throws DecryptionException
     * @throws AuthenticationException
     * @throws TooManyRequestsException
     */
    public function peekLock(int $timeout = 60): ?Message;

    /**
     * Deletes a previously locked message (see peekLock method).
     *
     * @param string $messageId
     * @param string $lockToken
     * @throws MessageNotFoundException
     * @throws InvalidClientDataException
     * @throws FifaConnectServiceBusSdkException
     * @throws UnauthorizedException
     * @throws AuthenticationException
     * @throws TooManyRequestsException
     */
    public function delete(string $messageId, string $lockToken);

    /**
     * Unlocks a previously locked message. The message is returned to the queue and can be fetched using peekLock or receive method.
     *
     * @param string $messageId
     * @param string $lockToken
     * @throws MessageNotFoundException
     * @throws InvalidClientDataException
     * @throws FifaConnectServiceBusSdkException
     * @throws UnauthorizedException
     * @throws AuthenticationException
     * @throws TooManyRequestsException
     */
    public function unlock(string $messageId, string $lockToken);
}