<?php
namespace App\Entity\Participation;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Controller\Api\Participation\Refund\GetParticipationRefundsByUser;
use App\Controller\Api\Participation\Refund\RefundPurseExpiringByUser;
use App\Entity\Purse\ItemStep as Item;
use App\Repository\Participation\RefundRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use JMS\Serializer\Annotation\ExclusionPolicy;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\SerializedName;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=RefundRepository::class)
* @ExclusionPolicy("all")
* @ApiResource(
* messenger=true,
* shortName="participation-refund",
* attributes={
* "normalization_context"={
* "groups"={
* "ParticipationRefund:output",
* "ParticipationRefund:io",
* }
* },
* "denormalization_context"={
* "groups"={
* "ParticipationRefund:input",
* "ParticipationRefund:io",
* }
* }
* },
* collectionOperations={
* "post"={
* "method"="POST",
* "access_control"="is_granted('ROLE_USER')"
* },
* "get"={
* "method"="GET",
* "access_control"="is_granted('ROLE_USER')",
* },
* "get-by-user"={
* "method"="GET",
* "path"="/participation-refunds/user",
* "access_control"="is_granted('ROLE_USER')",
* "validation_groups"={"get_participation-refunds_by_user"},
* "controller"=GetParticipationRefundsByUser::class,
* "defaults"={"_api_receive"=false},
* },
* "refund-purse-expiring-post"={
* "method"="POST",
* "path"="/participation-refunds/purse-expiring",
* "access_control"="is_granted('ROLE_USER')",
* "controller"=RefundPurseExpiringByUser::class,
* "defaults"={"_api_receive"=false},
* },
* },
* itemOperations={
* "get"={
* "method"="GET",
* "access_control"="is_granted('ROLE_USER')",
* },
* },
* )
*/
class Refund extends Participation
{
/**
* @ORM\Column(name="amount", type="float")
* @SerializedName("amount")
* @Groups({
* "ParticipationRefund:output"
* })
* @Assert\NotBlank(groups={"refund_process"})
* @Assert\Positive(groups={"refund_process"})
* @Assert\GreaterThan(value="0", groups={"refund_process"})
* @Assert\LessThanOrEqual(value="200", groups={"refund_process"})
*/
private ?float $amount = null;
/**
* @var string
* @ORM\Column(type="string")
* @Groups({
* "ParticipationRefund:io"
* })
* @Assert\NotBlank()
*
* @Serializer\Expose()
* @Serializer\Groups({"shannon_refund"})
*/
private $iban;
/**
* @var string
* @ORM\Column(type="string")
* @Groups({
* "ParticipationRefund:io"
* })
* @Assert\NotBlank()
* @Assert\Bic()
*
* @Serializer\Expose()
* @Serializer\Groups({"shannon_refund"})
*/
private $bic;
/**
* @ORM\OneToMany(targetEntity=Item::class, mappedBy="refund")
*/
private $items;
public function __construct()
{
parent::__construct();
$this->items = new ArrayCollection();
}
/**
* @return float|null
*/
public function getAmount() : ?float
{
return $this->amount;
}
/**
* @param float|null $amount
*
* @return Refund
*/
public function setAmount(?float $amount) : Refund
{
$this->amount = $amount;
return $this;
}
/**
* @return string
*/
public function getIban(): string
{
return $this->iban;
}
/**
* @param string $iban
* @return Refund
*/
public function setIban(string $iban): Refund
{
$this->iban = $iban;
return $this;
}
/**
* @return string
*/
public function getBic(): string
{
return $this->bic;
}
/**
* @param string $bic
* @return Refund
*/
public function setBic(string $bic): Refund
{
$this->bic = $bic;
return $this;
}
/**
* @return Collection|Item[]
*/
public function getItems(): Collection
{
return $this->items;
}
public function addItem(Item $item): self
{
if (!$this->items->contains($item)) {
$this->items[] = $item;
$item->setRefund($this);
}
return $this;
}
public function removeItem(Item $item): self
{
if ($this->items->removeElement($item)) {
// set the owning side to null (unless already changed)
if ($item->getRefund() === $this) {
$item->setRefund(null);
}
}
return $this;
}
/**
* @Serializer\VirtualProperty
* @Serializer\Groups({"shannon"})
* @Serializer\SerializedName("participation_id")
* @return string
*/
public function getParticipationId(): string
{
return $this->id;
}
/**
* Get opt-in RGPD.
*
* @Serializer\VirtualProperty
* @Serializer\Groups({"shannon"})
* @Serializer\SerializedName("optin_rgpd")
* @return int
*/
public function intOptInRGPD(): int
{
return true;
}
/**
* @Serializer\VirtualProperty
* @Serializer\Groups({"shannon"})
* @Serializer\SerializedName("action")
* @return string
*/
public function getAction(): string
{
return 'create';
}
/**
* @Serializer\VirtualProperty
* @Serializer\Groups({"shannon"})
* @Serializer\SerializedName("channel")
* @return string
*/
public function getChannel(): string
{
return 'FI';
}
/**
* @Serializer\VirtualProperty
* @Serializer\Groups({"shannon"})
* @Serializer\SerializedName("date_participation")
* @return string
*/
public function getDateParticipation(): string
{
return $this->getCreatedAt()->format('Y-m-d H:i:s');
}
public function getApiCode(): ?string
{
return $this->getValidationExport() instanceof ValidationExport ? $this->getValidationExport()->getAPIParticpationId() : null;
}
}