<?php

namespace AppBundle\Entity\Core;

use AppBundle\Annotation\ExportSplitFields;
use Doctrine\Common\Collections\ArrayCollection;
use AppBundle\Entity\Person\Person;
use Doctrine\ORM\Mapping as ORM;
use Dunglas\ApiBundle\Annotation\Iri;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use AppBundle\Entity\Traits\TimestampableEntity;
use AppBundle\Entity\Traits\CreatorUpdaterEntity;
use AppBundle\Annotation\Confidentiality;
use AppBundle\Validator\Constraints as OpentalentAssert;

/**
 * Subclass of: ContactPoint Source: GoodRelationsProperties.
 * Coordonnées postales des Person, des Organization et des Places
 *
 * @Iri("http://schema.org/AddressPostal")
 */
#[ORM\Entity(repositoryClass: 'AppBundle\Entity\Core\Repository\AddressPostalRepository')]
#[ORM\Table(name: 'AddressPostal')]
#[ORM\Index(name: 'viewIndex', columns: ['streetAddress', 'streetAddressSecond', 'streetAddressThird'])]
class AddressPostal
{
    use TimestampableEntity;
    use CreatorUpdaterEntity;
    /**
     * @var int
     */
    #[ORM\Column(type: 'integer')]
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    #[Groups(['addresspostal', 'organizationaddresspostal_reference', 'place_list', 'access_details_guardians', 'student_registration_person', 'student_registration_guardians', 'accesses_list_person', 'student_list_person', 'guardians_list_person', 'teachers_list_person', 'adherent_list_person', 'personnels_list_person', 'ca_list_person', 'othercontact_list_person', 'planning_list_addresspostal', 'board_list_person', 'place_reference', 'planning_list', 'placesystem_reference', 'organization_cotisation_steps_organizationaddresspostal'])]
    private $id;
    /**
     * @var Country
     */
    #[ORM\ManyToOne(targetEntity: 'Country')]
    #[Groups(['addresspostal', 'access_details_person', 'place_list_addresspostal', 'report_card_person', 'report_card_guardians', 'student_registration_person', 'student_registration_guardians', 'networkmanagers_list_person', 'access_duplicate_control_list_person', 'sepa_debit_mandate_person', 'student_list_guardians', 'organization_cotisation_steps_organizationaddresspostal', 'equipment_availability_form_borrower', 'view_from_manager_create_person', 'online_registration_access_details_person', 'build_bills_access', 'organization_params_list_organizationaddresspostal'])]
    private $addressCountry;
    /**
     * @var string
     *
     * @Confidentiality(visibility=\AppBundle\Enum\Confidentiality\ConfidentialityTypeEnum::VISIBILITY_PUBLIC)
     */
    #[ORM\Column(type: 'string', length: 100, nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Assert\Length(max: 100, maxMessage: 'invalid-max-length')]
    #[Groups(['addresspostal', 'access_details_person', 'morals_list_person', 'place_list_addresspostal', 'report_card_person', 'report_card_guardians', 'access_details_guardians', 'student_registration_person', 'student_registration_guardians', 'accesses_list_person', 'student_list_person', 'education_student_next_year_access', 'guardians_list_person', 'teachers_list_person', 'adherent_list_person', 'personnels_list_person', 'ca_list_person', 'othercontact_list_person', 'access_duplicate_control_list_person', 'board_list_person', 'network_list_organizationaddresspostal', 'federations_list_organizationaddresspostal', 'networkmanagers_list_organization', 'network_artist_school_list_organizationaddresspostal', 'networkmanagers_list_person', 'place_reference_addresspostal', 'placesystem_reference_addresspostal', 'organization_details_organizationaddresspostal', 'all_accesses_list_person', 'payer_list_person', 'planning_detail_place', 'template', 'sepa_debit_mandate_person', 'student_list_guardians', 'organization_cotisation_steps_organizationaddresspostal', 'equipment_availability_form_borrower', 'activity_report', 'view_from_manager_create_person', 'planning_list', 'online_registration_access_details_person', 'cmf_network_organizations_organizationaddresspostalprincipal', 'build_bills_access', 'organization_params_list_organizationaddresspostal'])]
    private $addressCity;
    /**
     * @var string
     */
    #[ORM\Column(type: 'string', length: 100, nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Assert\Length(max: 100, maxMessage: 'invalid-max-length')]
    #[Groups(['addresspostal', 'organization_cotisation_steps_organizationaddresspostal'])]
    private $addressOwner;
    /**
     * @var string
     *
     * @OpentalentAssert\PostalCode
     * @Confidentiality(visibility=\AppBundle\Enum\Confidentiality\ConfidentialityTypeEnum::VISIBILITY_PUBLIC)
     */
    #[ORM\Column(type: 'string', length: 20, nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Groups(['addresspostal', 'access_details_person', 'place_list_addresspostal', 'report_card_person', 'report_card_guardians', 'access_details_guardians', 'student_registration_person', 'student_registration_guardians', 'accesses_list_person', 'student_list_person', 'education_student_next_year_access', 'guardians_list_person', 'teachers_list_person', 'adherent_list_person', 'personnels_list_person', 'ca_list_person', 'othercontact_list_person', 'access_duplicate_control_list_person', 'board_list_person', 'network_list_organizationaddresspostal', 'federations_list_organizationaddresspostal', 'networkmanagers_list_organization', 'network_artist_school_list_organizationaddresspostal', 'networkmanagers_list_person', 'place_reference_addresspostal', 'placesystem_reference_addresspostal', 'all_accesses_list_person', 'organization_details_organizationaddresspostal', 'payer_list_person', 'planning_detail_place', 'template', 'sepa_debit_mandate_person', 'student_list_guardians', 'organization_cotisation_steps_organizationaddresspostal', 'equipment_availability_form_borrower', 'view_from_manager_create_person', 'planning_list', 'online_registration_access_details_person', 'cmf_network_organizations_organizationaddresspostalprincipal', 'build_bills_access', 'organization_params_list_organizationaddresspostal'])]
    private $postalCode;
    /**
     * @var string
     *
     * @Confidentiality(visibility=\AppBundle\Enum\Confidentiality\ConfidentialityTypeEnum::VISIBILITY_PUBLIC)
     */
    #[ORM\Column(type: 'string', nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Groups(['addresspostal', 'access_details_person', 'organizationaddresspostal_reference_addresspostal', 'place_list_addresspostal', 'report_card_person', 'report_card_guardians', 'access_details_guardians', 'student_registration_person', 'student_registration_guardians', 'accesses_list_person', 'student_list_person', 'education_student_next_year_access', 'guardians_list_person', 'teachers_list_person', 'adherent_list_person', 'personnels_list_person', 'ca_list_person', 'othercontact_list_person', 'access_duplicate_control_list_person', 'board_list_person', 'network_list_organizationaddresspostal', 'federations_list_organizationaddresspostal', 'networkmanagers_list_organization', 'network_artist_school_list_organizationaddresspostal', 'networkmanagers_list_person', 'organization_details_organizationaddresspostal', 'all_accesses_list_person', 'payer_list_person', 'planning_detail_place', 'template', 'sepa_debit_mandate_person', 'student_list_guardians', 'organization_cotisation_steps_organizationaddresspostal', 'equipment_availability_form_borrower', 'view_from_manager_create_person', 'planning_list', 'online_registration_access_details_person', 'cmf_network_organizations_organizationaddresspostalprincipal', 'build_bills_access', 'organization_params_list_organizationaddresspostal'])]
    private $streetAddress;
    /**
     * @var string
     *
     * @Confidentiality(visibility=\AppBundle\Enum\Confidentiality\ConfidentialityTypeEnum::VISIBILITY_PUBLIC)
     */
    #[ORM\Column(type: 'string', nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Groups(['addresspostal', 'access_details_person', 'organizationaddresspostal_reference_addresspostal', 'place_list_addresspostal', 'report_card_person', 'report_card_guardians', 'access_details_guardians', 'student_registration_person', 'student_registration_guardians', 'accesses_list_person', 'student_list_person', 'education_student_next_year_access', 'guardians_list_person', 'teachers_list_person', 'adherent_list_person', 'personnels_list_person', 'ca_list_person', 'othercontact_list_person', 'access_duplicate_control_list_person', 'board_list_person', 'network_list_organizationaddresspostal', 'federations_list_organizationaddresspostal', 'networkmanagers_list_organization', 'network_artist_school_list_organizationaddresspostal', 'all_accesses_list_person', 'networkmanagers_list_person', 'organization_details_organizationaddresspostal', 'payer_list_person', 'planning_detail_place', 'template', 'sepa_debit_mandate_person', 'student_list_guardians', 'organization_cotisation_steps_organizationaddresspostal', 'equipment_availability_form_borrower', 'view_from_manager_create_person', 'planning_list', 'online_registration_access_details_person', 'cmf_network_organizations_organizationaddresspostalprincipal', 'build_bills_access', 'organization_params_list_organizationaddresspostal'])]
    private $streetAddressSecond;
    /**
     * @var string
     *
     * @Confidentiality(visibility=\AppBundle\Enum\Confidentiality\ConfidentialityTypeEnum::VISIBILITY_PUBLIC)
     */
    #[ORM\Column(type: 'string', nullable: true)]
    #[Assert\Type(type: 'string')]
    #[Groups(['addresspostal', 'access_details_person', 'organizationaddresspostal_reference_addresspostal', 'place_list_addresspostal', 'report_card_person', 'report_card_guardians', 'access_details_guardians', 'student_registration_person', 'student_registration_guardians', 'accesses_list_person', 'student_list_person', 'education_student_next_year_access', 'guardians_list_person', 'teachers_list_person', 'adherent_list_person', 'personnels_list_person', 'ca_list_person', 'othercontact_list_person', 'access_duplicate_control_list_person', 'board_list_person', 'network_list_organizationaddresspostal', 'federations_list_organizationaddresspostal', 'networkmanagers_list_organization', 'network_artist_school_list_organizationaddresspostal', 'networkmanagers_list_person', 'organization_details_organizationaddresspostal', 'payer_list_person', 'all_accesses_list_person', 'planning_detail_place', 'template', 'sepa_debit_mandate_person', 'student_list_guardians', 'organization_cotisation_steps_organizationaddresspostal', 'equipment_availability_form_borrower', 'view_from_manager_create_person', 'planning_list', 'online_registration_access_details_person', 'cmf_network_organizations_organizationaddresspostalprincipal', 'build_bills_access', 'organization_params_list_organizationaddresspostal'])]
    private $streetAddressThird;
    /**
     * @var float
     */
    #[ORM\Column(type: 'float', nullable: true)]
    #[Assert\Type(type: 'float')]
    #[Groups(['addresspostal', 'organization_cotisation_steps_organizationaddresspostal'])]
    private $latitude;
    /**
     * @var float
     */
    #[ORM\Column(type: 'float', nullable: true)]
    #[Assert\Type(type: 'float')]
    #[Groups(['addresspostal', 'organization_cotisation_steps_organizationaddresspostal'])]
    private $longitude;
    /**
     * @var ArrayCollection<Place>
     */
    #[ORM\OneToMany(targetEntity: 'AppBundle\Entity\Place\Place', mappedBy: 'addressPostal')]
    #[Groups(['addresspostal_place'])]
    private $places;
    /**
     * @var ArrayCollection<Place>
     */
    #[ORM\OneToMany(targetEntity: 'AppBundle\Entity\Person\PersonAddressPostal', mappedBy: 'addressPostal')]
    private $personAddressPostal;
    /**
     * @var string
     * @ExportSplitFields({"streetAddress","streetAddressSecond","streetAddressThird","postalCode","addressCity"})
     */
    #[Groups(['template'])]
    private $fullLabelTemplate;
    /**
     * @var string
     */
    #[Groups(['template', 'addresspostal'])]
    private $addressPostalFormat;
    /**
     * Constructor
     */
    public function __construct()
    {
        $this->places = new ArrayCollection();
        $this->personAddressPostal = new ArrayCollection();
    }
    /**
     * Sets id.
     *
     * @param int $id
     *
     * @return $this
     */
    public function setId($id)
    {
        $this->id = $id;

        return $this;
    }
    /**
     * Gets id.
     *
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }
    /**
     * Sets addressCountry.
     *
     * @param Country $addressCountry
     *
     * @return $this
     */
    public function setAddressCountry(Country $addressCountry = null)
    {
        $this->addressCountry = $addressCountry;

        return $this;
    }
    /**
     * Gets addressCountry.
     *
     * @return Country
     */
    public function getAddressCountry()
    {
        return $this->addressCountry;
    }
    /**
     * Sets addressCity.
     *
     * @param string $addressCity
     *
     * @return $this
     */
    public function setAddressCity($addressCity)
    {
        $this->addressCity = $addressCity;

        return $this;
    }
    /**
     * Gets addressCity.
     *
     * @return string
     */
    public function getAddressCity()
    {
        return $this->addressCity;
    }
    /**
     * Sets postalCode.
     *
     * @param string $postalCode
     *
     * @return $this
     */
    public function setPostalCode($postalCode)
    {
        $this->postalCode = $postalCode;

        return $this;
    }
    /**
     * Gets postalCode.
     *
     * @return string
     */
    public function getPostalCode()
    {
        return $this->postalCode;
    }
    /**
     * Sets streetAddress.
     *
     * @param string $streetAddress
     *
     * @return $this
     */
    public function setStreetAddress($streetAddress)
    {
        $this->streetAddress = $streetAddress;

        return $this;
    }
    /**
     * Gets streetAddress.
     *
     * @return string
     */
    public function getStreetAddress()
    {
        return $this->streetAddress;
    }
    /**
     * Sets streetAddressSecond.
     *
     * @param string $streetAddressSecond
     *
     * @return $this
     */
    public function setStreetAddressSecond($streetAddressSecond)
    {
        $this->streetAddressSecond = $streetAddressSecond;

        return $this;
    }
    /**
     * Gets streetAddressSecond.
     *
     * @return string
     */
    public function getStreetAddressSecond()
    {
        return $this->streetAddressSecond;
    }
    /**
     * Sets streetAddressThird.
     *
     * @param string $streetAddressThird
     *
     * @return $this
     */
    public function setStreetAddressThird($streetAddressThird)
    {
        $this->streetAddressThird = $streetAddressThird;

        return $this;
    }
    /**
     * Gets streetAddressThird.
     *
     * @return string
     */
    public function getStreetAddressThird()
    {
        return $this->streetAddressThird;
    }
    /**
     * Sets latitude.
     *
     * @param float $latitude
     *
     * @return $this
     */
    public function setLatitude($latitude)
    {
        $this->latitude = floatval($latitude);

        return $this;
    }
    /**
     * Gets latitude.
     *
     * @return float
     */
    public function getLatitude()
    {
        return $this->latitude;
    }
    /**
     * Sets longitude.
     *
     * @param float $longitude
     *
     * @return $this
     */
    public function setLongitude($longitude)
    {
        $this->longitude = floatval($longitude);

        return $this;
    }
    /**
     * Gets longitude.
     *
     * @return float
     */
    public function getLongitude()
    {
        return $this->longitude;
    }
    public function getLocation() {
        if (null === $this->getLatitude() || null === $this->getLongitude()) {
            return null;
        }

        return $this->getLatitude().','.$this->getLongitude();
    }
    /**
     * @return string
     */
    public function getAddressOwner()
    {
        return $this->addressOwner;
    }
    /**
     * @param string $addressOwner
     */
    public function setAddressOwner($addressOwner)
    {
        $this->addressOwner = $addressOwner;
    }
    /**
     * Add place
     *
     * @param \AppBundle\Entity\Place\Place $place
     *
     * @return AddressPostal
     */
    public function addPlace(\AppBundle\Entity\Place\Place $place)
    {
        $this->places[] = $place;

        return $this;
    }
    /**
     * Remove place
     *
     * @param \AppBundle\Entity\Place\Place $place
     */
    public function removePlace(\AppBundle\Entity\Place\Place $place)
    {
        $this->places->removeElement($place);
    }
    /**
     * Get places
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getPlaces()
    {
        return $this->places;
    }
    /**
     * Get person address postal
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getPersonAddressPostal()
    {
        return $this->personAddressPostal;
    }
    /**
     * Gets full label.
     *
     * @return string
     */
    public function getFullLabelTemplate()
    {
        $fullAddressArray = [];

        if(!empty($this->getStreetAddress()))
            $fullAddressArray[] = $this->getStreetAddress();

        if(!empty($this->getStreetAddressSecond()))
            $fullAddressArray[] = $this->getStreetAddressSecond();

        if(!empty($this->getStreetAddressThird()))
            $fullAddressArray[] = $this->getStreetAddressThird();

        if(!empty($this->getPostalCode()))
            $fullAddressArray[] = $this->getPostalCode();

        if(!empty($this->getAddressCity()))
            $fullAddressArray[] = $this->getAddressCity();

        return implode(" ", $fullAddressArray);
    }
    /**
     * Gets full label.
     *
     * @return string
     */
    public function getAddressPostalFormat()
    {
        $fullAddressArray = [];

        if(!empty($this->getStreetAddress()))
            $fullAddressArray[] = $this->getStreetAddress();

        if(!empty($this->getStreetAddressSecond()))
            $fullAddressArray[] = $this->getStreetAddressSecond();

        if(!empty($this->getStreetAddressThird()))
            $fullAddressArray[] = $this->getStreetAddressThird();

        $cityAndPostCodeArray = [];
        if(!empty($this->getPostalCode()))
            $cityAndPostCodeArray[] = $this->getPostalCode();

        if(!empty($this->getAddressCity()))
            $cityAndPostCodeArray[] = $this->getAddressCity();


        $fullAddressArray[] = implode(" ", $cityAndPostCodeArray);

        return  implode("<br />", $fullAddressArray);
    }
    /**
     * Add personAddressPostal
     *
     * @param \AppBundle\Entity\Person\PersonAddressPostal $personAddressPostal
     *
     * @return AddressPostal
     */
    public function addPersonAddressPostal(\AppBundle\Entity\Person\PersonAddressPostal $personAddressPostal)
    {
        $this->personAddressPostal[] = $personAddressPostal;

        return $this;
    }
    /**
     * Remove personAddressPostal
     *
     * @param \AppBundle\Entity\Person\PersonAddressPostal $personAddressPostal
     */
    public function removePersonAddressPostal(\AppBundle\Entity\Person\PersonAddressPostal $personAddressPostal)
    {
        $this->personAddressPostal->removeElement($personAddressPostal);
    }
}
