<?php

/*
 * This file is part of the Serenity package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Behavior\Impl;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Intl\Countries;
use Symfony\Component\Validator\Constraints as Assert;

trait Geocodable
{
    #[ORM\Column(type: 'text', nullable: true)]
    private ?string $address = null;

    #[ORM\Column(type: 'text')]
    #[Assert\NotBlank]
    private ?string $postal = null;

    #[ORM\Column(type: 'text')]
    #[Assert\NotBlank]
    private ?string $city = null;

    #[ORM\Column(type: 'text')]
    #[Assert\NotBlank]
    private ?string $country = null;

    #[ORM\Column(type: 'text', nullable: true)]
    private ?string $lat = null;

    #[ORM\Column(type: 'text', nullable: true)]
    private ?string $lng = null;

    public function getAddress(): ?string
    {
        return $this->address;
    }

    public function setAddress(?string $address): void
    {
        $this->address = $address;
    }

    public function getPostal(): ?string
    {
        return $this->postal;
    }

    public function setPostal(?string $postal): void
    {
        if (null !== $postal) {
            $this->postal = str_replace(' ', '', $postal);
        } else {
            $this->postal = null;
        }
    }

    public function getCity(): ?string
    {
        return $this->city;
    }

    public function setCity(?string $city): void
    {
        $this->city = $city;
    }

    public function getCountry(): ?string
    {
        return $this->country;
    }

    public function setCountry(?string $country): void
    {
        $this->country = $country;
    }

    public function getLat(): ?string
    {
        return $this->lat;
    }

    public function setLat(?string $lat): void
    {
        $this->lat = $lat;
    }

    public function getLng(): ?string
    {
        return $this->lng;
    }

    public function setLng(?string $lng): void
    {
        $this->lng = $lng;
    }

    public function getCountryName(): ?string
    {
        if (!$this->country) {
            return null;
        }

        return Countries::getName($this->country);
    }
}
