<?php
/**
 * @package   Essentials YOOtheme Pro 2.2.16 build 0813.1608
 * @author    ZOOlanders https://www.zoolanders.com
 * @copyright Copyright (C) Joolanders, SL
 * @license   http://www.gnu.org/licenses/gpl.html GNU/GPL
 */

namespace ZOOlanders\YOOessentials\Source\Provider\Facebook\Type;

use ZOOlanders\YOOessentials\Source\GraphQL\TypeInterface;

// https://developers.facebook.com/docs/graph-api/reference/page
class FacebookPlaceType implements TypeInterface
{
    public const TYPE_NAME = 'FacebookPlace';
    public const TYPE_LABEL = 'Facebook Place';

    public function type(): string
    {
        return TypeInterface::TYPE_OBJECT;
    }

    public function name(): string
    {
        return self::TYPE_NAME;
    }

    public function label(): string
    {
        return self::TYPE_LABEL;
    }

    public function config(): array
    {
        return [
            'fields' => [
                'name' => [
                    'type' => 'String',
                    'metadata' => [
                        'label' => 'Name',
                        'filters' => ['limit'],
                    ],
                ],
                'city' => [
                    'type' => 'String',
                    'metadata' => [
                        'label' => 'City',
                        'filters' => ['limit'],
                    ],
                ],
                'country' => [
                    'type' => 'String',
                    'metadata' => [
                        'label' => 'Country',
                        'filters' => ['limit'],
                    ],
                ],
                'street' => [
                    'type' => 'String',
                    'metadata' => [
                        'label' => 'Street',
                        'filters' => ['limit'],
                    ],
                ],
                'zip' => [
                    'type' => 'String',
                    'metadata' => [
                        'label' => 'Zip Code',
                        'filters' => ['limit'],
                    ],
                ],
                'latitude' => [
                    'type' => 'String',
                    'metadata' => [
                        'label' => 'Latitude'
                    ],
                ],
                'longitude' => [
                    'type' => 'String',
                    'metadata' => [
                        'label' => 'Longitude'
                    ],
                ],
            ],

            'metadata' => [
                'type' => true,
                'label' => $this->label(),
            ],
        ];
    }

    public static function resolve($place): array
    {
        return $place['location'] + ['name' => $place['name']];
    }
}
