<?php

declare(strict_types=1);

namespace App\Support\Ui\ActionSurface;

use App\Support\Ui\ActionSurface\Enums\ActionSurfaceProfile;
use App\Support\Ui\ActionSurface\Enums\ActionSurfaceSlot;
use App\Support\Ui\ActionSurface\Enums\ActionSurfaceType;

final class ActionSurfaceProfileDefinition
{
    /**
     * @return array<int, ActionSurfaceSlot>
     */
    public function requiredSlots(ActionSurfaceProfile $profile): array
    {
        return match ($profile) {
            ActionSurfaceProfile::CrudListAndEdit,
            ActionSurfaceProfile::CrudListAndView => [
                ActionSurfaceSlot::ListHeader,
                ActionSurfaceSlot::InspectAffordance,
                ActionSurfaceSlot::ListRowMoreMenu,
                ActionSurfaceSlot::ListBulkMoreGroup,
                ActionSurfaceSlot::ListEmptyState,
                ActionSurfaceSlot::DetailHeader,
            ],
            ActionSurfaceProfile::ListOnlyReadOnly => [
                ActionSurfaceSlot::ListHeader,
                ActionSurfaceSlot::InspectAffordance,
                ActionSurfaceSlot::ListRowMoreMenu,
                ActionSurfaceSlot::ListBulkMoreGroup,
                ActionSurfaceSlot::ListEmptyState,
            ],
            ActionSurfaceProfile::RunLog => [
                ActionSurfaceSlot::ListHeader,
                ActionSurfaceSlot::InspectAffordance,
                ActionSurfaceSlot::ListBulkMoreGroup,
                ActionSurfaceSlot::ListEmptyState,
                ActionSurfaceSlot::DetailHeader,
            ],
            ActionSurfaceProfile::RelationManager => [
                ActionSurfaceSlot::ListHeader,
                ActionSurfaceSlot::InspectAffordance,
                ActionSurfaceSlot::ListRowMoreMenu,
                ActionSurfaceSlot::ListBulkMoreGroup,
                ActionSurfaceSlot::ListEmptyState,
            ],
        };
    }

    public function requiresExportDefaultBulk(ActionSurfaceProfile $profile): bool
    {
        return in_array($profile, [
            ActionSurfaceProfile::ListOnlyReadOnly,
            ActionSurfaceProfile::RunLog,
        ], true);
    }

    /**
     * @return array<int, ActionSurfaceType>
     */
    public function allowedSurfaceTypes(ActionSurfaceProfile $profile): array
    {
        return match ($profile) {
            ActionSurfaceProfile::CrudListAndEdit,
            ActionSurfaceProfile::CrudListAndView => [
                ActionSurfaceType::CrudListFirstResource,
                ActionSurfaceType::ReadOnlyRegistryReport,
                ActionSurfaceType::ConfigLite,
            ],
            ActionSurfaceProfile::ListOnlyReadOnly => [
                ActionSurfaceType::ReadOnlyRegistryReport,
            ],
            ActionSurfaceProfile::RunLog => [
                ActionSurfaceType::ReadOnlyRegistryReport,
                ActionSurfaceType::QueueReview,
                ActionSurfaceType::HistoryAudit,
            ],
            ActionSurfaceProfile::RelationManager => [
                ActionSurfaceType::CrudListFirstResource,
                ActionSurfaceType::ReadOnlyRegistryReport,
            ],
        };
    }

    public function allowsSurfaceType(ActionSurfaceProfile $profile, ActionSurfaceType $surfaceType): bool
    {
        return in_array($surfaceType, $this->allowedSurfaceTypes($profile), true);
    }
}
