<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Trait\TimestampableEntity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
#[ORM\Entity]
#[ApiResource(
iri: 'MarketRumorPort',
collectionOperations: [],
itemOperations: [
'get' => [
'security' => "is_granted('ROLE_USER')",
'method' => 'GET',
'path' => '/market_rumors/ports/{id}',
'openapi_context' => [
'tags' => ['MarketRumor / Port']
]
]
],
attributes: ['pagination_enabled' => false]
)]
class MarketRumorPort
{
use TimestampableEntity;
public const PORT_CALL_TYPE_LOAD = 'Load';
public const PORT_CALL_TYPE_DISCHARGE = 'Discharge';
public const PORT_CALL_TYPES = [
self::PORT_CALL_TYPE_LOAD,
self::PORT_CALL_TYPE_DISCHARGE
];
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'NONE')]
#[ORM\Column(type: 'uuid', unique: true)]
private ?UuidInterface $id = null;
#[ORM\Column(type: 'string', nullable: false)]
#[ApiProperty()]
#[Assert\NotBlank]
#[Assert\Type('string')]
#[Assert\Choice(
choices: self::PORT_CALL_TYPES,
message: 'The type is not valid.'
)]
#[Groups([
'market_rumor:item:get',
'market_rumor:item:put',
'market_rumor:collection:get',
'market_rumor:collection:post'
])]
private ?string $portCallType = null;
#[ORM\ManyToOne(
targetEntity: Port::class,
inversedBy: 'portCalls'
)]
#[ORM\JoinColumn(nullable: true)]
#[ApiProperty()]
#[Groups([
'market_rumor:item:get',
'market_rumor:item:put',
'market_rumor:collection:get',
'market_rumor:collection:post'
])]
#[MaxDepth(1)]
private ?Port $port = null;
#[ORM\Column(type: 'integer')]
#[Assert\NotNull]
#[ApiProperty()]
#[Groups([
'market_rumor:item:get',
'market_rumor:item:put',
'market_rumor:collection:get',
'market_rumor:collection:post'
])]
private ?int $portIndex = 0;
#[ORM\ManyToOne(
targetEntity: MarketRumor::class,
inversedBy: 'portCalls'
)]
#[ORM\JoinColumn(nullable: true)]
private ?MarketRumor $marketRumor = null;
public function __construct()
{
$this->id = Uuid::uuid4();
}
public function getId(): ?UuidInterface
{
return $this->id;
}
public function setPortCallType(?string $portCallType): void
{
$this->portCallType = $portCallType;
}
public function getPortCallType(): ?string
{
return $this->portCallType;
}
public function setPort(?Port $port): void
{
$this->port = $port;
}
public function getPort(): ?Port
{
return $this->port;
}
public function setPortIndex(?int $portIndex): void
{
$this->portIndex = $portIndex;
}
public function getPortIndex(): ?int
{
return $this->portIndex;
}
public function setMarketRumor(?MarketRumor $marketRumor): void
{
$this->marketRumor = $marketRumor;
}
public function getMarketRumor(): ?MarketRumor
{
return $this->marketRumor;
}
}