<?php

namespace NoahVet\Reef\RabbitMQ\Notification;

use NoahVet\Reef\Domain\Security\Model\Resource;

class ReefNotification implements ReefNotificationInterface
{
    /**
     * Client name of App generating the notification.
     *
     * @example reef:bsmApi
     */
    public readonly string $clientId;

    /**
     * Resource type of the subject.
     *
     * @example reef:bsmApi:veterinaryEstablishment
     */
    public readonly string $resourceType;

    /**
     * Resource id (excluding resourceType Part).
     *
     * @example ec17f420-363d-4b27-ad3d-4d4dd6eeda34
     */
    public readonly string $resourceId;

    /**
     * The action performed on the resource (must be a fully qualified IAM permission slug).
     *
     * @example reef:bsmApi:veterinaryEstablishment:perm:updatePublic
     * @example reef:iam:resourceType:perm:create (Creation of a new resource).
     */
    public readonly string $action;

    /**
     * @var array<string, string|int|float|bool|array<string, string|int|float|bool>>
     */
    public readonly array $rawData;

    /**
     * @param array<string, string|int|float|bool|array<string, string|int|float|bool>> $rawData
     */
    public function __construct(
        string $clientId,
        string $resourceType,
        string $resourceId,
        string $action,
        array $rawData)
    {
        $this->clientId = $clientId;
        $this->resourceType = $resourceType;
        $this->resourceId = $resourceId;
        $this->action = $action;
        $this->rawData = $rawData;
    }

    #[\Override]
    public function getClientId(): string
    {
        return $this->clientId;
    }

    #[\Override]
    public function getResource(): Resource
    {
        return Resource::fromString($this->resourceType, $this->resourceId);
    }

    #[\Override]
    public function getAction(): string
    {
        return $this->action;
    }

    #[\Override]
    public function getRawData(): array
    {
        return $this->rawData;
    }
}
