<?php

namespace Shm\ShmChat\Classes;

use Shm\ShmChat\ShmChatService;

class ChatChannelContext
{
    public function __construct(
        private readonly string $channelId,
    ) {
    }

    public function sendMessage(
        ChatMember $sender,
        string $text = '',
        ?string $reply = null,
        ?string $clientMessageId = null,
    ): object {
        return ShmChatService::sendMessage(new SendMessageInput(
            channelId: $this->channelId,
            sender: $sender,
            text: $text,
            reply: $reply,
            clientMessageId: $clientMessageId,
        ));
    }

    public function sendSystem(string $text, ?ChatMember $by = null): object
    {
        return ShmChatService::sendSystemMessage($this->channelId, $text, $by);
    }

    public function close(?ChatMember $by = null): bool
    {
        return ShmChatService::closeChannel($this->channelId, $by);
    }

    public function markRead(ChatMember $reader, ?string $lastReadMessageId = null): void
    {
        ShmChatService::markRead($this->channelId, $reader, $lastReadMessageId);
    }

    public function addMember(ChatMember $member): bool
    {
        return ShmChatService::addMember($this->channelId, $member);
    }

    public function addReference(ChannelReference $ref): bool
    {
        return ShmChatService::addReference($this->channelId, $ref);
    }

    public function removeReference(ChannelReference $ref): bool
    {
        return ShmChatService::removeReference($this->channelId, $ref);
    }

    /**
     * @return array{data?: array<int, mixed>, hash: string}
     */
    public function listMessages(ListQueryInput $query): array
    {
        return ShmChatService::listMessages($this->channelId, $query);
    }

    public function deleteMessage(string $messageId, ChatMember $by): bool
    {
        return ShmChatService::deleteMessage($this->channelId, $messageId, $by);
    }

    public function toggleReaction(string $messageId, string $reaction, ChatMember $user): bool
    {
        return ShmChatService::toggleReaction($this->channelId, $messageId, $reaction, $user);
    }
}
