<?php

class Dalten_Export_Api_NewRealitymix extends Dalten_Export_Api_SrealityLike
{
    protected function _convertListingData(array $listingData, array $additionalParams)
    {
        $originalListingData = $listingData;
        $listingData = parent::_convertListingData($listingData, $additionalParams);

        $hidePortals = '00';
        if (isset($additionalParams['listing']['hide_portals'])) {
            // data dostáváme v podobě pole integerů, když v něm je integer s danou hodnotou pošleme ho
            // 1=Prima HbbTV
            $hidePortals[1] = in_array(1, $additionalParams['listing']['hide_portals']) ? 1 : 0;
        }
        $listingData['hide_portals'] = $hidePortals;

        // z původních (nepřevedených) dat vytáhneme video
        $youtubeIdVideo = Dalten_Export_Helper_YoutubeIdExtractor::extractYoutubeId($originalListingData['nemovitost_video_prohlidka']);
        if ($youtubeIdVideo) {
            $listingData['video_url'] = $originalListingData['nemovitost_video_prohlidka'];
        }

        $youtubeIdVirtualniProhlidka = Dalten_Export_Helper_YoutubeIdExtractor::extractYoutubeId($originalListingData['nemovitost_virtualni_prohlidka']);
        if ($youtubeIdVirtualniProhlidka) {
            $listingData['video_url'] = $originalListingData['nemovitost_virtualni_prohlidka'];
        }

        return $listingData;
    }

    protected function getProjectUrl($remoteId)
    {
        return sprintf('https://realitymix.cz/detail-projektu/lokalita/nahled-%d.html', $remoteId);
    }


    /**
     * {@inheritDoc}
     */
    public function topListing(array $listingData, array $additionalParams = [])
    {
        $response = $this->_backend->topAdvert(
            $this->_getSessionId(),
            null,
            isset($listingData['kod']) ? $listingData['kod'] : null
        );

        return new Dalten_Export_Api_ServerResponse(
            $response->status == 200,
            $response->status,
            $response->statusMessage,
            $response->output
        );
    }
}
