<?php

namespace App\Core\Service;

use App\Core\Repository\Property\PropertyRepository;
use App\Core\Repository\PropertyWebPhotoMapping\PropertyWebPhotoMappingRepository;
use App\Core\Service\PropertyAdditionalInfo\PropertyAdditionalInfoService;
use App\Core\Service\PropertyExecutiveService;
use App\Core\Service\PropertyPhotoService\PropertyPhotoService;
use App\Core\Service\PropertyRoomService;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use \App\Core\Service\PropertyFactService;
use \App\Core\Service\PropertyWebColorMappingService;

use Illuminate\Support\Facades\Log;
use Exception;
use App\Exceptions\ApiErrorException;
use Illuminate\Support\Facades\Config;
use Carbon\Carbon;


class PdfContentService
{

    private $propertyRepository;
    private $propertyAdditionalInfoService;
    private $propertyContactService;
    private $propertyFactService;
    private $propertyPhotoService;
    private $propertyRoomService;
    private $propertyExecutiveService;
    private $propertyWebPhotoMappingRepository;
    private $propertyWebColorMappingService;
    private $propertyPlaceService;

    public function __construct(
        PropertyRepository $propertyRepository,
        PropertyAdditionalInfoService $propertyAdditionalInfoService,
        PropertyContactService $propertyContactService,
        PropertyFactService $propertyFactService,
        PropertyPhotoService $propertyPhotoService,
        PropertyRoomService $propertyRoomService,
        PropertyExecutiveService $propertyExecutiveService,
        PropertyWebPhotoMappingRepository $propertyWebPhotoMappingRepository,
        PropertyWebColorMappingService $propertyWebColorMappingService,
        PropertyPlaceService $propertyPlaceService


    )
    {
        $this->propertyRepository = $propertyRepository;
        $this->propertyAdditionalInfoService = $propertyAdditionalInfoService;
        $this->propertyContactService = $propertyContactService;
        $this->propertyFactService = $propertyFactService;
        $this->propertyPhotoService = $propertyPhotoService;
        $this->propertyRoomService = $propertyRoomService;
        $this->propertyExecutiveService = $propertyExecutiveService;
        $this->propertyWebPhotoMappingRepository = $propertyWebPhotoMappingRepository;
        $this->propertyWebColorMappingService = $propertyWebColorMappingService;
        $this->propertyPlaceService = $propertyPlaceService;

    }


    public function pdfData($params = [])
    {

        $response = ['status' => -1, 'message' => '', 'data' => null];
        try {

            $propertyRequest = [
                'criteria' => [
                    ['field' => 'id', 'condition' => '=', 'value' => $params['property_id']],
                    ['field' => 'status', 'condition' => '=', 'value' => 1],
                ],
                'with' => [
                    'propertyBrand', 'propertyContact', 'propertyPhotos', 'propertyType', 'propertyChain',
                    'propertyRooms.propertyRoomType', 'propertyExecutive.executiveType',
                    'propertyLanguageSpoken.languageCode', 'propertyAwardsCertificates.awardsCertificateCategory'
                ],
                'firstRow' => true
            ];


            $getPropertyFields = [
                'id', 'name', 'property_type_id', 'chain_id', 'rating', 'official_name', 'tax_office', 'tax_number', 'currency_type', 'country'
            ];
            $property = $this->propertyRepository->findByCriteria($propertyRequest, $getPropertyFields);

            //dd($property['property_rooms']);

            if (!$property) {
                throw new ApiErrorException('property not found');
            }

            $newExecutiveArray = [];
            foreach ($property['property_executive'] as $propertyExecutive) {

                $executiveItem = [
                    'id' => $propertyExecutive['id'],
                    'executive_type_name' => $propertyExecutive['executive_type']['name'],
                    'executive_type_locale_key' => $propertyExecutive['executive_type']['language_key'],
                    'executive_type_icon' => $propertyExecutive['executive_type']['icon'],
                    'name_surname' => $propertyExecutive['name_surname'],
                    'email' => $propertyExecutive['email'],
                    'phone_code' => $propertyExecutive['phone_code'],
                    'phone' => $propertyExecutive['phone'],
                    'extension' => $propertyExecutive['extension'],
                    'mobile_code' => $propertyExecutive['mobile_code'],
                    'mobile' => $propertyExecutive['mobile'],
                    'fax_code' => $propertyExecutive['fax_code'],
                    'fax' => $propertyExecutive['fax'],
                    'view_full_phone' => $propertyExecutive['view_full_phone'],
                    'view_full_mobile' => $propertyExecutive['view_full_mobile'],
                    'view_full_fax' => $propertyExecutive['view_full_fax'],
                ];

                if ($propertyExecutive['status'] == 1) {
                    $newExecutiveArray[] = $executiveItem;
                }

            }

            $getPropertyFact = $this->propertyFactService->getPropertyFact($params);
            if ($getPropertyFact['status'] != 'success') {
                throw new ApiErrorException($getPropertyFact['message']);
            }

            $getPropertyFact = $this->getPropertyFactForHtml($getPropertyFact['data']);
            if ($getPropertyFact['status'] != 'success') {
                throw new ApiErrorException($getPropertyFact['message']);
            }

            $responseData = [
                'name' => $property['name'],
                'property_type' => fillOnUndefined($property['property_type'], 'name'),
                'property_type_language_key' => fillOnUndefined($property['property_type'], 'language_key'),
                'property_type_key' => fillOnUndefined($property['property_type'], 'language_key'),
                'property_chain' => fillOnUndefined($property['property_chain'], 'name'),
                'official_name' => $property['official_name'],
                'tax_office' => $property['tax_office'],
                'tax_number' => $property['tax_number'],
                'currency_type' => $property['currency_type'],
                'country' => $property['country'],
                'description' => $property['name'],
                'rooms' => $property['property_rooms'],
                'property_brand' => $property['property_brand'],
                'property_contact' => $property['property_contact'],
                'property_facts' => $getPropertyFact['data'],
                'property_executive' => $newExecutiveArray,
            ];

            $propertyAdditionalInfo = $this->propertyAdditionalInfoService->getPropertyAdditionalInfo2KeyBy($params);
            if (isset($propertyAdditionalInfo['data'])) {
                $responseData['additional_info'] = $propertyAdditionalInfo['data'];
            }


            $responseData['property_language_spoken'] = null;
            if ($property['property_language_spoken']) {
                foreach ($property['property_language_spoken'] as $language) {
                    $responseData['property_language_spoken'][] = __($language['language_code']['language_key']);
                }
                if ($responseData['property_language_spoken']) {
                    $responseData['property_language_spoken'] = implode(', ', $responseData['property_language_spoken']);
                }
            }


            $responseData['property_awards_certificates'] = null;
            if ($property['property_awards_certificates']) {
                foreach ($property['property_awards_certificates'] as $certificate) {
                    if ($certificate['status'] == 1) {
                        $responseData['property_awards_certificates'][] = $certificate['awards_certificate_category']['name'] . (!empty($certificate['date']) ? ' (' . $certificate['date'] . ')' : '');
                    }
                }
                if ($responseData['property_awards_certificates']) {
                    $responseData['property_awards_certificates'] = implode(', ', $responseData['property_awards_certificates']);
                }
            }

            $propertyPlaceCriteria = [
                'criteria' =>
                    [
                        ['field' => 'property_id', 'condition' => '=', 'value' => $params['property_id']],
                        ['field' => 'status', 'condition' => '!=', 'value' => 0],
                        //['field' => 'id', 'condition' => '=', 'value' => 5],//TODO: Del
                    ],
                'with' => [
                    'propertyPlaceCategory', 'propertyPlaceWorkingHour',
                    'propertyPlaceFactMapping.propertyPlaceFactTitleFactMapping.placeFact',
                    'propertyPlaceFactMapping.propertyPlaceFactTitleFactMapping.placeFactTitle',
                    'propertyPlaceCategoryFieldValue.placeCategoryField',
                    'propertyPlaceCategoryFieldValue.unitValue',
                    'propertyPlaceCategoryFieldValue.optionValue'
                ],
                'orderBy' => [["field" => "order_number", "value" => "ASC"]],
            ];
            $propertyPlaces = $this->propertyPlaceService->select($propertyPlaceCriteria);
            $propertyPlaces = $propertyPlaces['data'] ? $propertyPlaces['data'] : [];


            foreach ($propertyPlaces as $placeKey => $propertyPlace) {

                $propertyPlaceFactGroups = collect($propertyPlace['property_place_fact_mapping'])->groupBy('property_place_fact_title_fact_mapping.place_fact_title.id');
                $propertyPlaceFactGroups = $propertyPlaceFactGroups->toArray();

                $propertyPlaceFactMapping = [];
                foreach ($propertyPlaceFactGroups as $propertyPlaceFactGroupKey => $propertyPlaceFactGroup) {
                    foreach ($propertyPlaceFactGroup as $propertyPlaceFact) {
                        $propertyPlaceFactMapping[$propertyPlaceFactGroupKey]['title'] = $propertyPlaceFact['property_place_fact_title_fact_mapping']['place_fact_title']['language_key'];
                        $propertyPlaceFactMapping[$propertyPlaceFactGroupKey]['fact'][] = $propertyPlaceFact['property_place_fact_title_fact_mapping']['place_fact']['language_key'];
                    }
                }

                unset($propertyPlaces[$placeKey]['property_place_fact_mapping']);

                $propertyPlaces[$placeKey]['property_place_fact_mapping'] = $propertyPlaceFactMapping;

            }

            $responseData['propertyPlaces'] = $propertyPlaces;

            $response = [
                'status' => true,
                'data' => $responseData,
            ];

        } catch (ApiErrorException $e) {
            $response['message'] = $e->getMessage();
        } catch (Exception $e) {
            $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
            Log::error($message);
            $response['message'] = $e->getMessage();
        }

        return output($response);
    }

    public function getPropertyFactForHtml($params = [])
    {
        $response = ['status' => -1, 'message' => '', 'data' => null];
        try {
            $categories = $params;
            $responseArray = [];
            foreach ($categories as $category) {
                $categoryArray = [];
                $categoryItem = $category;
                foreach ($category['fact_subcategory'] as $subCategory) {
                    $subCategoryItem = $subCategory;
                    $facts = collect($subCategory['fact'])
                        ->where('is_selected', '=', true)
                        ->map(function ($value) {
                            return $value;
                        })->values()->all();
                    $subCategoryItem['fact'] = $facts ? $facts : [];
                    if ($facts) {
                        $categoryArray[$subCategory['id']] = $subCategoryItem;
                    }
                }
                $categoryItem['fact_subcategory'] = $categoryArray;
                $responseArray[$category['id']] = $categoryItem;
            }

            $response = [
                'status' => true,
                'data' => $responseArray,
            ];

        } catch (ApiErrorException $e) {
            $response['message'] = $e->getMessage();
        } catch (Exception $e) {
            $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
            Log::error($message);
            $response['message'] = $e->getMessage();
        }

        return output($response);

    }

    public function propertyBaseData($params = [])
    {

        $response = ['status' => -1, 'message' => '', 'data' => null];
        try {

            $propertyRequest = [
                'criteria' => [
                    ['field' => 'id', 'condition' => '=', 'value' => $params['property_id']],
                    ['field' => 'status', 'condition' => '=', 'value' => 1],
                ],
                'with' => ['propertyBrand', 'propertyContact'],
                'firstRow' => true
            ];


            $getPropertyFields = ['id', 'name', 'property_type_id', 'chain_id', 'rating', 'official_name', 'tax_office', 'tax_number', 'currency_type', 'country'];
            $property = $this->propertyRepository->findByCriteria($propertyRequest, $getPropertyFields);

            if (!$property) {
                throw new ApiErrorException('property not found');
            }

            $response = [
                'status' => true,
                'data' => $property,
            ];

        } catch (ApiErrorException $e) {
            $response['message'] = $e->getMessage();
        } catch (Exception $e) {
            $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
            Log::error($message);
            $response['message'] = $e->getMessage();
        }

        return output($response);
    }


    public function factSheetData($params = [])
    {

        $response = ['status' => -1, 'message' => '', 'data' => null];

        $factSheetData = [];

        try {

            $propertyRequest = [
                'criteria' => [
                    ['field' => 'id', 'condition' => '=', 'value' => $params['property_id']],
                    ['field' => 'status', 'condition' => '=', 'value' => 1],
                ],
                'with' => [
                    'propertyBrand', 'propertyContact', 'propertyPhotos', 'propertyType', 'propertyChain',
                    'propertyExecutive.executiveType', 'propertyLanguageSpoken.languageCode', 'propertyAwardsCertificates.awardsCertificateCategory',
                    'propertyRooms.propertyRoomType', 'propertyRooms.propertyRoomFactMapping.propertyFact',
                    'propertyRooms.propertyRoomPhotoMapping.propertyRoomPhoto',
                    'propertyRooms.propertyRoomViewMapping.propertyRoomViewType',
                    'propertyFactMapping.fact.propertyFactParent.propertyFactParent', 'propertyBookingEngineToken',
                    'propertyPlace.propertyPlaceCategory', 'propertyPlace.propertyPlaceWorkingHour',
                    'propertyPlace.propertyPlaceFactMapping.propertyPlaceFactTitleFactMapping.placeFact',
                    'propertyPlace.propertyPlaceFactMapping.propertyPlaceFactTitleFactMapping.placeFactTitle',
                    'propertyPlace.propertyPlaceCategoryFieldValue.placeCategoryField',
                    'propertyPlace.propertyPlaceCategoryFieldValue.unitValue',
                    'propertyPlace.propertyPlaceCategoryFieldValue.optionValue',
                    'propertyPlace.propertyPlacePhotoMapping.propertyPlacePhoto',
                    'propertyAdditionalInfos.propertyAdditionalInfoKey'
                ],
                'firstRow' => true
            ];

            $getPropertyFields = ['id', 'name', 'property_type_id', 'chain_id', 'rating', 'official_name', 'tax_office', 'tax_number', 'currency_type', 'country'];
            $property = $this->propertyRepository->findByCriteria($propertyRequest, $getPropertyFields);

            if (!$property) {
                throw new ApiErrorException('Property not found');
            }


            //colorCodes
            $colorCodes = null;
            $colorCodesArray = json_decode($property['property_brand']['color_codes'], 1);
            $colorCodes = array_values($colorCodesArray);

            //summary
            $summary = null;
            $summaryArray = json_decode($property['property_brand']['title'], 1);
            $summary = isset($summaryArray[$params['locale']]) ? $summaryArray[$params['locale']] : null;


            //propertyFact
            $propertyFact = null;
            $amenities = collect($property['property_fact_mapping'])->where('fact.property_fact_parent.property_fact_parent.id',1)->toArray();
            $propertyFact['amenities']['name'] = __('property_fact-amenities',[],$params['locale']);
            foreach ($amenities as $propertyFactMapping) {

                $propertyFact['amenities']['fact'][$propertyFactMapping['fact']['property_fact_parent']['id']]['name'] = __($propertyFactMapping['fact']['property_fact_parent']['language_key'],[],$params['locale']);
                $propertyFact['amenities']['fact'][$propertyFactMapping['fact']['property_fact_parent']['id']]['order_number'] = $propertyFactMapping['fact']['property_fact_parent']['order_number'];
                $propertyFact['amenities']['fact'][$propertyFactMapping['fact']['property_fact_parent']['id']]['fact'][$propertyFactMapping['fact']['id']] = [
                    'name' => __($propertyFactMapping['fact']['language_key'],[],$params['locale']),
                    'icon' => $propertyFactMapping['fact']['icon'],
                ];
                $propertyFact['amenities']['fact'][$propertyFactMapping['fact']['property_fact_parent']['id']]['fact'] = array_values($propertyFact['amenities']['fact'][$propertyFactMapping['fact']['property_fact_parent']['id']]['fact']);
            }
            $propertyFact['amenities']['fact'] = collect($propertyFact['amenities']['fact'])->sortBy('order_number')->toArray();
            $propertyFact['amenities']['fact'] = array_values($propertyFact['amenities']['fact']);

            $facilities = collect($property['property_fact_mapping'])->where('fact.property_fact_parent.property_fact_parent.id',44)->toArray();
            $propertyFact['facilities']['name'] = __('property_fact-facilities',[],$params['locale']);
            foreach ($facilities as $propertyFactMapping) {

                $propertyFact['facilities']['fact'][$propertyFactMapping['fact']['property_fact_parent']['id']]['name'] = __($propertyFactMapping['fact']['property_fact_parent']['language_key'],[],$params['locale']);
                $propertyFact['facilities']['fact'][$propertyFactMapping['fact']['property_fact_parent']['id']]['order_number'] = $propertyFactMapping['fact']['property_fact_parent']['order_number'];
                $propertyFact['facilities']['fact'][$propertyFactMapping['fact']['property_fact_parent']['id']]['fact'][$propertyFactMapping['fact']['id']] = [
                    'name' => __($propertyFactMapping['fact']['language_key'],[],$params['locale']),
                    'icon' => $propertyFactMapping['fact']['icon'],
                ];
                $propertyFact['facilities']['fact'][$propertyFactMapping['fact']['property_fact_parent']['id']]['fact'] = array_values($propertyFact['facilities']['fact'][$propertyFactMapping['fact']['property_fact_parent']['id']]['fact']);
            }
            $propertyFact['facilities']['fact'] = collect($propertyFact['facilities']['fact'])->sortBy('order_number')->toArray();
            $propertyFact['facilities']['fact'] = array_values($propertyFact['facilities']['fact']);


            //propertyPhoto
            $propertyPhoto = [];
            foreach ($property['property_photos'] as $propertyPhotos) {
                $propertyPhoto[] = [
                    'photo_order' => $propertyPhotos['photo_order'],
                    'is_default' => $propertyPhotos['is_default'],
                    'is_compatible_slider' => $propertyPhotos['is_compatible_with_myweb_slider'],
                    'photoUrl' => $propertyPhotos['photoUrl'],
                ];
            }
            $propertyPhoto = collect($propertyPhoto)->sortBy('photo_order')->toArray();
            $propertyPhoto = array_values($propertyPhoto);


            //propertyAwardsCertificate
            $propertyAwardsCertificate = [];
            foreach ($property['property_awards_certificates'] as $propertyAwardsCertificateMapping) {
                $propertyAwardsCertificate[] = [
                    'name' => $propertyAwardsCertificateMapping['awards_certificate_category']['name'],
                    'type' => $propertyAwardsCertificateMapping['awards_certificate_category']['type'],
                ];
            }

            //propertyExecutive
            $propertyExecutive = [];
            foreach ($property['property_executive'] as $propertyExecutives) {
                $propertyExecutive[] = [
                    'name' => $propertyExecutives['name_surname'],
                    'type' => __($propertyExecutives['executive_type']['language_key'],[],$params['locale']),
                    'email' => $propertyExecutives['email'],
                    'phone' => $propertyExecutives['view_full_phone'],
                    'mobile' => $propertyExecutives['view_full_mobile'],
                    'fax' => $propertyExecutives['view_full_fax'],
                ];
            }


            //propertyAwardsCertificate
            $propertyAdditionalInfo = [];
            foreach ($property['property_additional_infos'] as $propertyAdditionalInfos) {
                $propertyAdditionalInfo[] = [
                    'id' => $propertyAdditionalInfos['additional_info_key_id'],
                    'name' => __($propertyAdditionalInfos['property_additional_info_key']['language_key'],[],$params['locale']),
                    'key' => $propertyAdditionalInfos['property_additional_info_key']['additional_info_key'],
                    'language_key' => $propertyAdditionalInfos['property_additional_info_key']['language_key'],
                    'value' => $propertyAdditionalInfos['value'],
                ];
            }

            //propertyRoom
            $propertyRoom = [];
            foreach ($property['property_rooms'] as $propertyRooms) {

                $propertyRoom[$propertyRooms['id']] = [
                    'name' => $propertyRooms['name'],
                    'type' => __($propertyRooms['property_room_type']['language_key'],[],$params['locale']),
                    'max_occupancy' => $propertyRooms['max_occupancy'],
                    'max_adult' => $propertyRooms['max_adult'],
                    'max_child' => $propertyRooms['max_child'],
                    'max_child_number' => $propertyRooms['max_child_number'],
                    'room_size' => $propertyRooms['room_size'],
                    'room_size_type' => $propertyRooms['roomSizeTypeFormatted'],
                    'room_count' => $propertyRooms['room_count']
                ];

                //propertyRoomFact
                $propertyRoomFact = null;
                foreach ($propertyRooms['property_room_fact_mapping'] as $propertyRoomFactMapping) {
                    $propertyRoomFact[$propertyRoomFactMapping['property_fact']['id']] = [
                        'name' => __($propertyRoomFactMapping['property_fact']['language_key'],[],$params['locale']),
                        'icon' => $propertyRoomFactMapping['property_fact']['icon'],
                    ];
                    $propertyRoomFact = array_values($propertyRoomFact);
                }

                $propertyRoomFact = collect($propertyRoomFact)->sortBy('order_number')->toArray();
                $propertyRoomFact = array_values($propertyRoomFact);
                $propertyRoom[$propertyRooms['id']]['fact'] = $propertyRoomFact;

                //propertyRoomPhoto
                $propertyRoomPhoto = null;
                foreach ($propertyRooms['property_room_photo_mapping'] as $propertyRoomPhotoMapping) {
                    $propertyRoomPhoto[] = [
                        'photo_order' => $propertyRoomPhotoMapping['property_room_photo']['photo_order'],
                        'is_default' => $propertyRoomPhotoMapping['property_room_photo']['is_default'],
                        'photoUrl' => $propertyRoomPhotoMapping['property_room_photo']['photoUrl'],
                    ];
                }
                $propertyRoomPhoto = collect($propertyRoomPhoto)->sortBy('photo_order')->toArray();

                //dd($propertyRoomPhoto);
                $propertyRoomPhoto = array_values($propertyRoomPhoto);
                $propertyRoom[$propertyRooms['id']]['photo'] = $propertyRoomPhoto;

                //propertyRoomView
                $propertyRoomView = null;
                foreach ($propertyRooms['property_room_view_mapping'] as $propertyRoomViewMapping) {
                    $propertyRoomView[] = [
                        'name' => __($propertyRoomViewMapping['property_room_view_type']['language_key'],[],$params['locale']),
                    ];
                }
                $propertyRoom[$propertyRooms['id']]['view'] = $propertyRoomView;

            }

            $propertyRoom = array_values($propertyRoom);


            //propertyPlace
            $propertyPlace = [];
            foreach ($property['property_place'] as $propertyPlaces) {


                //$description
                $description = null;
                $descriptionArray = json_decode($propertyPlaces['description'], 1);
                $description = isset($descriptionArray[$params['locale']]) ? $descriptionArray[$params['locale']] : null;


                //propertyPlaceFact
                $propertyPlaceFact = null;
                foreach ($propertyPlaces['property_place_fact_mapping'] as $propertyPlaceFactMapping) {
                    $propertyPlaceFact[$propertyPlaceFactMapping['property_place_fact_title_fact_mapping']['place_fact_title']['id']]['name'] = __($propertyPlaceFactMapping['property_place_fact_title_fact_mapping']['place_fact_title']['language_key']);
                    $propertyPlaceFact[$propertyPlaceFactMapping['property_place_fact_title_fact_mapping']['place_fact_title']['id']]['fact'][$propertyPlaceFactMapping['property_place_fact_title_fact_mapping']['place_fact']['id']] = [
                        'name' => __($propertyPlaceFactMapping['property_place_fact_title_fact_mapping']['place_fact']['language_key'],[],$params['locale']),
                        'icon' => $propertyPlaceFactMapping['property_place_fact_title_fact_mapping']['place_fact']['icon'],
                    ];
                    $propertyPlaceFact[$propertyPlaceFactMapping['property_place_fact_title_fact_mapping']['place_fact_title']['id']]['fact'] = array_values($propertyPlaceFact[$propertyPlaceFactMapping['property_place_fact_title_fact_mapping']['place_fact_title']['id']]['fact']);
                }
                $propertyPlaceFact = collect($propertyPlaceFact)->sortBy('order_number')->toArray();
                $propertyPlaceFact = array_values($propertyPlaceFact);


                //propertyPlaceFact
                $propertyPlaceField = null;
                foreach ($propertyPlaces['property_place_category_field_value'] as $propertyPlaceCategoryField) {
                    $propertyPlaceField[] = [
                        'id' => $propertyPlaceCategoryField['place_category_field']['id'],
                        'name' => __($propertyPlaceCategoryField['place_category_field']['language_key'],[],$params['locale']),
                        'element' => $propertyPlaceCategoryField['place_category_field']['element'],
                        'input_value' => $propertyPlaceCategoryField['input_value'],
                        'option_value' => $propertyPlaceCategoryField['option_value'],
                        'unit' => isset($propertyPlaceCategoryField['unit_value']) ? __($propertyPlaceCategoryField['unit_value']['language_key'],[],$params['locale']) : null,
                        'unit_short_name' => isset($propertyPlaceCategoryField['unit_value']) ? $propertyPlaceCategoryField['unit_value']['short_name'] : null,
                    ];
                }

                //propertyPlacePhoto
                $propertyPlacePhoto= null;
                foreach ($propertyPlaces['property_place_photo_mapping'] as $propertyPlacePhotoMapping) {
                    $propertyPlacePhoto[] = [
                        'photo_order' => $propertyPlacePhotoMapping['property_place_photo']['photo_order'],
                        'is_default' => $propertyPlacePhotoMapping['property_place_photo']['is_default'],
                        'photoUrl' => $propertyPlacePhotoMapping['property_place_photo']['photoUrl'],
                    ];
                }
                $propertyPlacePhoto = collect($propertyPlacePhoto)->sortBy('photo_order')->toArray();
                $propertyPlacePhoto = array_values($propertyPlacePhoto);



                $propertyPlace[$propertyPlaces['id']] = [
                    'name' => $propertyPlaces['name'],
                    'category' => __($propertyPlaces['property_place_category']['language_key'],[],$params['locale']),
                    'description' => $description,
                    'field' => $propertyPlaceField,
                    'fact' => $propertyPlaceFact,
                    'photo' => $propertyPlacePhoto
                ];


            }

            $propertyPlace = array_values($propertyPlace);


            $factSheetData = [
                'id' => $property['id'],
                'name' => $property['name'],
                'booking_engine_token' => isset($property['property_booking_engine_token']['token']) ? $property['property_booking_engine_token']['token'] : null,
                'property_type' => __(fillOnUndefined($property['property_type'], 'language_key'),[],$params['locale']),
                'property_chain' => __(fillOnUndefined($property['property_chain'], 'name'),[],$params['locale']),
                'property_brand' => [
                    'logoUrl' => $property['property_brand']['logoUrl'],
                    'colorCodes' => $colorCodes,
                    'summary' => $summary
                ],
                'property_contact' => [
                    'country' => $property['country'],
                    'address' => $property['property_contact']['address'],
                    'zip_code' => $property['property_contact']['zip_code'],
                    'latitude' => $property['property_contact']['latitude'],
                    'longitude' => $property['property_contact']['longitude'],
                    'phone' => $property['property_contact']['view_full_phone'],
                    'mobile' => $property['property_contact']['view_full_mobile'],
                    'fax' => $property['property_contact']['view_full_fax'],
                    'email' => $property['property_contact']['email'],
                    'web' => $property['property_contact']['web'],
                ],
                'property_executive' => $propertyExecutive,
                'property_awards_certificates' => $propertyAwardsCertificate,
                'property_fact' => $propertyFact,
                'property_photo' => $propertyPhoto,
                'property_room' => $propertyRoom,
                'property_place' => $propertyPlace,
                'additional_info' => $propertyAdditionalInfo

            ];

            $response = [
                'status' => true,
                'data' => $factSheetData,
            ];

        } catch (ApiErrorException $e) {
            $response['message'] = $e->getMessage();
        } catch (Exception $e) {
            $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
            Log::error($message);
            $response['message'] = $e->getMessage();
        }

        return output($response);
    }


}
