<?php

/*
 * This file is part of the Serenity package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Serenity\CoreBundle\Seed;

use Symfony\Component\Uid\Uuid;

final readonly class SeedPayload
{
    public function __construct(
        public Uuid $runId,
        public bool $dryRun,
        public ?string $saasIdentifier,
        public ?string $tag,
        public ?string $plan,
        public bool $activeOnly,
        public bool $global,
        public ?string $seeder,
    ) {
    }

    /** @return array<string, mixed> */
    public function toArray(): array
    {
        return [
            'runId' => $this->runId,
            'dryRun' => $this->dryRun,
            'saasIdentifier' => $this->saasIdentifier,
            'tag' => $this->tag,
            'plan' => $this->plan,
            'activeOnly' => $this->activeOnly,
            'global' => $this->global,
            'seeder' => $this->seeder,
        ];
    }

    /**
     * @throws \JsonException
     */
    public function lockKey(): string
    {
        $data = $this->toArray();
        unset($data['runId']);
        ksort($data);

        return 'seed:run:'.hash('xxh128', json_encode($data, \JSON_THROW_ON_ERROR));
    }
}
