<?php

declare(strict_types=1);

namespace Autogedal\FeedMonitor\Model;

/**
 * Identifies what an alert is about: a job, a sub-feed of a job ("job:feed") or the Magento cron itself.
 */
class MonitorKey
{
    public const MAGENTO_CRON = 'magento_cron';

    public static function build(string $jobCode, string $feedCode = ''): string
    {
        return $feedCode === '' ? $jobCode : $jobCode . ':' . $feedCode;
    }

    /**
     * @return array{0: string, 1: string} job code, feed code
     */
    public static function split(string $key): array
    {
        $parts = explode(':', $key, 2);

        return [$parts[0], $parts[1] ?? ''];
    }
}
