<?php

declare(strict_types=1);

namespace apexl\Io\modules\product\Enum\permissions;

use apexl\Io\modules\permissions\Interface\PermissionFlagInterface;
use apexl\Io\modules\user\interfaces\PermissionInterface;
use apexl\Io\modules\user\traits\IsPermissionTrait;

/**
 * Product catalogue permissions (V3). Consumers may grant these to their
 * own roles; defaults route to director/admin.
 */
enum ProductPermission implements PermissionInterface, PermissionFlagInterface, \JsonSerializable
{
    use IsPermissionTrait;

    case CAN_VIEW_PRODUCTS;
    case CAN_MANAGE_PRODUCTS;

    public function key(): string
    {
        return self::class . '::' . $this->name;
    }

    public function defaultRoleNames(): array
    {
        return match ($this) {
            self::CAN_VIEW_PRODUCTS   => ['director', 'admin', 'accounts', 'sales'],
            self::CAN_MANAGE_PRODUCTS => ['director', 'admin', 'accounts'],
        };
    }
}
