<?php
/**
 * BookiFlex Onboarding Extension
 *
 * @package    BookiFlex
 * @subpackage Onboarding
 * @author     BookiFlex
 * @copyright  Copyright (c) 2025 BookiFlex
 * @license    GPL-2.0-or-later
 *
 * @link       https://bookiflex.com
 */

declare(strict_types=1);

namespace BookiFlex\Extensions\Onboarding\ValueObject;

defined( 'ABSPATH' ) || exit;

/**
 * Onboarding Presets Value Object
 *
 * Encapsulates all version-specific preset data from AbstractPlugin::getOnboardingPresets().
 *
 * @package BookiFlex\Extensions\Onboarding\ValueObject
 * @since   1.0.0
 */
class OnboardingPresets
{
    /**
     * Onboarding Presets constructor
     *
     * @param array<int, array<string, mixed>>                 $cancellationPolicies CancellationPolicy preset templates
     * @param array<int, array<string, mixed>>                 $paymentTypes         PaymentType preset templates
     * @param array<string, array<int, array<string, string>>> $nextSteps            Mode-specific next steps
     * @param array<int, array<string, mixed>>                 $testDataTemplates    Sample accommodation data for test mode
     *
     * @throws \InvalidArgumentException If next steps for required modes are missing
     */
    public function __construct(
        public readonly array $cancellationPolicies,
        public readonly array $paymentTypes,
        public readonly array $nextSteps,
        public readonly array $testDataTemplates,
    ) {
        // Validate nextSteps has all required modes
        $requiredModes = ['quick_setup', 'test_data', 'manual'];
        foreach ($requiredModes as $mode) {
            if (!isset($this->nextSteps[$mode])) {
                throw new \InvalidArgumentException(
                    sprintf(
                        'Missing nextSteps for mode: %s',
                        $mode
                    )
                );
            }
        }
    }

    /**
     * Create from array
     *
     * @param  array<string, mixed> $data Array representation
     * @return self
     */
    public static function fromArray(array $data): self
    {
        return new self(
            cancellationPolicies: $data['cancellationPolicies'] ?? [],
            paymentTypes: $data['paymentTypes'] ?? [],
            nextSteps: $data['nextSteps'] ?? [],
            testDataTemplates: $data['testDataTemplates'] ?? [],
        );
    }

    /**
     * Get next steps for specific mode
     *
     * @param  OnboardingMode $mode Onboarding mode
     * @return array<int, array<string, string>> Next steps for mode
     */
    public function getNextStepsForMode(OnboardingMode $mode): array
    {
        return $this->nextSteps[$mode->value] ?? [];
    }

    /**
     * Get cancellation policies with transformed structure
     *
     * @return array<int, array<string, mixed>> Cancellation policy templates
     */
    public function getCancellationPolicies(): array
    {
        return $this->cancellationPolicies;
    }

    /**
     * Get payment types with transformed structure
     *
     * @return array<int, array<string, mixed>> Payment type templates
     */
    public function getPaymentTypes(): array
    {
        return $this->paymentTypes;
    }

    /**
     * Get test data templates
     *
     * @return array<int, array<string, mixed>> Test accommodation templates
     */
    public function getTestDataTemplates(): array
    {
        return $this->testDataTemplates;
    }
}
