<?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\Model\AccommodationType\Accommodation;

use BookiFlex\Core\Model\AccommodationType\Placement\PlacementRules;

defined( 'ABSPATH' ) || exit;

/**
 * Accommodation type entity
 */
class AccommodationType
{
    private int $id;
    private string $name;
    private ?string $accommodationCategory;
    private AccommodationCapacity $capacity;
    private PlacementRules $rules;
    private int $accommodationAvailableUnits;
    private array $metadata;

    /**
     * @param int $id
     * @param string $name Name of the accommodation type
     * @param string $accommodationCategory Type of the accommodation
     * @param AccommodationCapacity $capacity
     * @param PlacementRules $rules
     * @param int $accommodationAvailableUnits The total number of individual units of this accommodation type that can be booked. For example, 10 identical Double Rooms.
     * @param array $metadata
     */
    public function __construct(
        int $id,
        string $name,
        string $accommodationCategory,
        AccommodationCapacity $capacity,
        PlacementRules $rules,
        int $accommodationAvailableUnits,
        array $metadata = []
    ) {
        $this->id = $id;
        $this->name = $name;
        $this->accommodationCategory = $accommodationCategory;
        $this->capacity = $capacity;
        $this->rules = $rules;
        $this->accommodationAvailableUnits = $accommodationAvailableUnits;
        $this->metadata = $metadata;
    }

    public function getId(): int
    {
        return $this->id;
    }

    public function getName(): string
    {
        return $this->name;
    }

    public function getAccommodationCategory(): string
    {
        return $this->accommodationCategory;
    }

    public function getCapacity(): AccommodationCapacity
    {
        return $this->capacity;
    }

    public function getRules(): PlacementRules
    {
        return $this->rules;
    }

    public function getAccommodationAvailableUnits(): int
    {
        return $this->accommodationAvailableUnits;
    }

    public function getMetadata(): array
    {
        return $this->metadata;
    }

    public function getGallery(): array
    {
        return $this->metadata['gallery'] ?? [];
    }

    public function getThumbnail(): array
    {
        return $this->metadata['thumbnail'][0] ?? [];
    }

    public function getAmenities(): array
    {
        if (empty($this->metadata['amenities'])) {
            return [];
        }

        return array_map('trim', explode(',', $this->metadata['amenities']));
    }

    public function getShortCode(): string
    {
        return $this->metadata['shortCode'];
    }

    public function isActive(): bool
    {
        return $this->metadata['active'] ?? true;
    }
}
