|null */ private ?array $decisionZone = null; /** * @var list */ private array $mainSections = []; /** * @var list */ private array $supportingGroups = []; /** * @var list */ private array $technicalSections = []; /** * @var list */ private array $emptyStateNotes = []; public function __construct( private readonly string $resourceType, private readonly string $scope, ) {} public static function make(string $resourceType, string $scope): self { return new self($resourceType, $scope); } public function header(SummaryHeaderData $header): self { $this->header = $header; return $this; } /** * @param array $decisionZone */ public function decisionZone(array $decisionZone): self { $this->decisionZone = $decisionZone; return $this; } public function addSection(DetailSectionData ...$sections): self { foreach ($sections as $section) { $this->mainSections[] = $section; } return $this; } public function addSupportingCard(SupportingCardData ...$cards): self { return $this->addSupportingGroup(...$cards); } public function addSupportingGroup(SupportingCardData ...$groups): self { foreach ($groups as $group) { $this->supportingGroups[] = $group; } return $this; } public function addTechnicalSection(TechnicalDetailData ...$sections): self { foreach ($sections as $section) { $this->technicalSections[] = $section; } return $this; } /** * @param list $notes */ public function emptyStateNotes(array $notes): self { $this->emptyStateNotes = $notes; return $this; } public function build(): EnterpriseDetailPageData { if (! $this->header instanceof SummaryHeaderData) { throw new LogicException('Enterprise detail pages require a summary header.'); } return new EnterpriseDetailPageData( resourceType: $this->resourceType, scope: $this->scope, header: $this->header, decisionZone: is_array($this->decisionZone) && $this->decisionZone !== [] ? $this->decisionZone : null, mainSections: array_values(array_filter( $this->mainSections, static fn (DetailSectionData $section): bool => $section->shouldRender(), )), supportingGroups: array_values(array_filter( $this->supportingGroups, static fn (SupportingCardData $group): bool => $group->shouldRender(), )), technicalSections: array_values(array_filter( $this->technicalSections, static fn (TechnicalDetailData $section): bool => $section->shouldRender(), )), emptyStateNotes: $this->emptyStateNotes, ); } }