<?php

declare(strict_types=1);

namespace App\Support\Baselines\Compare;

use InvalidArgumentException;

final class CompareSubjectProjection
{
    /**
     * @param  array<string, string>  $additionalLabels
     * @param  array<string, mixed>|null  $subjectDescriptor
     */
    public function __construct(
        public readonly string $platformSubjectClass,
        public readonly string $domainKey,
        public readonly string $subjectTypeKey,
        public readonly string $operatorLabel,
        public readonly ?string $summaryKind = null,
        public readonly array $additionalLabels = [],
        public readonly ?array $subjectDescriptor = null,
    ) {
        if (trim($this->platformSubjectClass) === '' || trim($this->domainKey) === '' || trim($this->subjectTypeKey) === '' || trim($this->operatorLabel) === '') {
            throw new InvalidArgumentException('Compare subject projections require non-empty platform subject class, domain key, subject type key, and operator label values.');
        }
    }

    /**
     * @return array{
     *   platform_subject_class: string,
     *   domain_key: string,
     *   subject_type_key: string,
     *   operator_label: string,
     *   summary_kind: ?string,
    *   additional_labels: array<string, string>,
    *   subject_descriptor: ?array<string, mixed>
     * }
     */
    public function toArray(): array
    {
        return [
            'platform_subject_class' => $this->platformSubjectClass,
            'domain_key' => $this->domainKey,
            'subject_type_key' => $this->subjectTypeKey,
            'operator_label' => $this->operatorLabel,
            'summary_kind' => $this->summaryKind,
            'additional_labels' => $this->additionalLabels,
            'subject_descriptor' => $this->subjectDescriptor,
        ];
    }
}