<?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 Result Value Object
 *
 * Encapsulates onboarding execution outcome for API response.
 *
 * @package BookiFlex\Extensions\Onboarding\ValueObject
 * @since   1.0.0
 */
class OnboardingResult
{
    /**
     * Onboarding Result constructor
     *
     * @param bool           $success   Operation success flag
     * @param OnboardingMode $mode      Mode that was executed
     * @param NextStep[]     $nextSteps Array of next step recommendations
     */
    public function __construct(
        public readonly bool $success,
        public readonly OnboardingMode $mode,
        public readonly array $nextSteps,
    ) {
    }

    /**
     * Convert to array representation for API response
     *
     * @return array{success: bool, message: string, data: array{mode: string, nextSteps: array}}
     */
    public function toArray(): array
    {
        return [
            'success' => $this->success,
            'message' => __('Onboarding completed successfully', 'bookiflex'),
            'data' => [
                'mode' => $this->mode->value,
                'nextSteps' => array_map(fn(NextStep $step) => $step->toArray(), $this->nextSteps),
            ],
        ];
    }
}
