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

declare(strict_types=1);

namespace BookiFlex\Core\Api\Transformer;

use BookiFlex\Core\Model\AccommodationType\Accommodation\AccommodationType;

defined( 'ABSPATH' ) || exit;

/**
 * Transform AccommodationType entities for API responses
 */
class AccommodationTypeTransformer
{
    /**
     * Transform single accommodation type to API response format
     *
     * @param AccommodationType $accommodationType Accommodation type entity
     * @return array Transformed data
     */
    public function transform(AccommodationType $accommodationType): array
    {
        return [
            'id' => $accommodationType->getId(),
            'name' => $accommodationType->getName(),
            'defaultQuota' => $accommodationType->getAccommodationAvailableUnits(),
        ];
    }

    /**
     * Transform array of accommodation types
     *
     * @param AccommodationType[] $accommodationTypes Array of accommodation type entities
     * @return array Array of transformed accommodation types
     */
    public function transformCollection(array $accommodationTypes): array
    {
        return array_map(
            fn(AccommodationType $accommodationType) => $this->transform($accommodationType),
            $accommodationTypes
        );
    }
}