<?php

namespace Planaday\Entities\Location\DTO;

use DateTime;
use DateTimeZone;
use Planaday\Entities\CostsData;

class Location {
	protected string $name = '';
	protected string $code = '';
	protected string $street1 = '';
	protected string $street2 = '';
	protected string $houseNumber = '';
	protected string $houseNumberExtension = '';
	protected string $zipcode = '';
	protected string $city = '';
	protected string $country = '';
	protected string $lat = '';
	protected string $lng = '';
	protected string $phoneNumber = '';
	protected string $email = '';
	protected string $website = '';
	protected string $description = '';
	protected int $capacity = 0;
	protected bool $overbookable = false;
	protected bool $isVirtual = false;
	protected bool $isExternal = false;
	protected ?CostsData $costData = null;
	protected DateTime $lastUpdate;

	public function __construct(
		protected string $id
	) {
		$this->lastUpdate = (new DateTime())->setTimezone(new DateTimeZone('Europe/Amsterdam'));
	}

	public function setName( ?string $name ): self  {
		$this->name = $name ?? $this->name;

		return $this;
	}

	public function setCode( ?string $code ): self  {
		$this->code = $code ?? $this->code;

		return $this;
	}

	public function setStreet1( ?string $street1 ): self  {
		$this->street1 = $street1 ?? $this->street1;

		return $this;
	}

	public function setStreet2( ?string $street2 ): self  {
		$this->street2 = $street2 ?? $this->street2;

		return $this;
	}

	public function setHouseNumber( ?string $houseNumber ): self  {
		$this->houseNumber = $houseNumber ?? $this->houseNumber;

		return $this;
	}

	public function setHouseNumberExtension( ?string $houseNumberExtension ): self  {
		$this->houseNumberExtension = $houseNumberExtension ?? $this->houseNumberExtension;

		return $this;
	}

	public function setZipcode( ?string $zipcode ): self  {
		$this->zipcode = $zipcode ?? $this->zipcode;

		return $this;
	}

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

		return $this;
	}

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

		return $this;
	}

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

		return $this;
	}

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

		return $this;
	}

	public function setPhoneNumber( ?string $phoneNumber ): self  {
		$this->phoneNumber = $phoneNumber ?? $this->phoneNumber;

		return $this;
	}

	public function setEmail( ?string $email ): self  {
		$this->email = $email ?? $this->email;

		return $this;
	}

	public function setWebsite( ?string $website ): self  {
		$this->website = $website ?? $this->website;

		return $this;
	}

	public function setDescription( ?string $description ): self  {
		$this->description = $description ?? $this->description;

		return $this;
	}

	public function setCapacity( ?int $capacity ): self  {
		$this->capacity = $capacity ?? $this->capacity;

		return $this;
	}

	public function setOverbookable( ?bool $overbookable ): self  {
		$this->overbookable = $overbookable ?? $this->overbookable;

		return $this;
	}

	public function setIsVirtual( ?bool $isVirtual ): self  {
		$this->isVirtual = $isVirtual ?? $this->isVirtual;

		return $this;
	}

	public function setIsExternal( ?bool $isExternal ): self  {
		$this->isExternal = $isExternal ?? $this->isExternal;

		return $this;
	}

	public function setCostData( ?CostsData $costData ): self  {
		$this->costData = $costData;

		return $this;
	}

	public function setLastUpdate( DateTime $lastUpdate ): self  {
		$this->lastUpdate = $lastUpdate;

		return $this;
	}

	public function getId(): string {
		return $this->id;
	}

	public function getName(): string {
		return $this->name;
	}

	public function getCode(): string {
		return $this->code;
	}

	public function getStreet1(): string {
		return $this->street1;
	}

	public function getStreet2(): string {
		return $this->street2;
	}

	public function getHouseNumber(): string {
		return $this->houseNumber;
	}

	public function getHouseNumberExtension(): string {
		return $this->houseNumberExtension;
	}

	public function getZipcode(): string {
		return $this->zipcode;
	}

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

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

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

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

	public function getPhoneNumber(): string {
		return $this->phoneNumber;
	}

	public function getEmail(): string {
		return $this->email;
	}

	public function getWebsite(): string {
		return $this->website;
	}

	public function getDescription(): string {
		return $this->description;
	}

	public function getCapacity(): int {
		return $this->capacity;
	}

	public function isOverbookable(): bool {
		return $this->overbookable;
	}

	public function isVirtual(): bool {
		return $this->isVirtual;
	}

	public function isExternal(): bool {
		return $this->isExternal;
	}

	public function getCostData(): CostsData {
		if ( $this->costData === null ) {
			$this->costData = new CostsData();
		}

		return $this->costData;
	}

	public function getLastUpdate(): DateTime {
		return $this->lastUpdate;
	}

	public function getAge():int {
		return time() - $this->lastUpdate->getTimestamp();
	}
}