<?php
namespace App\Entity\Sponsorship;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\Sponsorship\SponsorshipRequestRepository;
use App\Controller\Api\SponsorshipRequest\PostSponsorshipRequestGodChild;
use App\Controller\Api\SponsorshipRequest\PostMultipleSponsorshipRequests;
use App\Controller\Api\SponsorshipRequest\GetGodFatherByGodChildEmail;
use App\Controller\Api\SponsorshipRequest\GetGodChildsByGodFatherUser;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\User\User;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Ramsey\Uuid\Uuid;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\SerializedName;
use Symfony\Component\Validator\Constraints as Assert;
use Ramsey\Uuid\Doctrine\UuidGenerator;
/**
* @ORM\Entity(repositoryClass=SponsorshipRequestRepository::class)
* @ORM\Table(name="sponsorship")
*
* @ApiResource(
* attributes={
* "normalization_context"={"groups"={
* "SponsorshipRequest:output",
* "SponsorshipRequest:io",
* "get_godfather_by_godchild_email",
* "get_godchilds_by_godfather_user",
* }},
* "denormalization_context"={"groups"={
* "SponsorshipRequest:input",
* "SponsorshipRequest:io",
* "get_godfather_by_godchild_email",
* "get_godchilds_by_godfather_user",
* }}
* },
* collectionOperations={
* "get",
* "get-recovery-godchilds-by-godfather-user"={
* "method"="GET",
* "path"="/sponsorship_requests/recovery-godchilds/user",
* "access_control"="is_granted('ROLE_USER')",
* "validation_groups"={"get_godchilds_by_godfather_user"},
* "controller"=GetGodChildsByGodFatherUser::class,
* "defaults"={"_api_receive"=false},
* },
* "post",
* "post-godchild-by-user"={
* "method"="POST",
* "path"="public/sponsorship_requests/get-godchild",
* "validation_groups"={"post_godchild_sponsorship_request"},
* "controller"=PostSponsorshipRequestGodChild::class,
* "defaults"={"_api_receive"=false},
* },
* "post-multiple-sponsorchip-requests"={
* "method"="POST",
* "path"="/sponsorship_requests/multiple",
* "access_control"="is_granted('ROLE_USER')",
* "controller"=PostMultipleSponsorshipRequests::class,
* "defaults"={"_api_receive"=false},
* },
* },
* itemOperations={
* "get",
* "get-recovery-godfther-by-godchild-email"={
* "method"="GET",
* "path"="/sponsorship_requests/recovery-godfather/user",
* "access_control"="is_granted('ROLE_USER')",
* "validation_groups"={"get_godfather_by_godchild_email"},
* "controller"=GetGodFatherByGodChildEmail::class,
* "defaults"={"_api_receive"=false},
* },
* }
* )
*
*/
class SponsorshipRequest
{
const STATUS_WAITING = "waiting_for_registration";
const STATUS_IN_PROGRESS = "in_process_of_registration";
const STATUS_FULLY_REGISTERED = "fully_registered";
const STATUS_GODCHILD_DELETED = "godchild_deleted";
/**
* Hook timestampable behavior
* updates createdAt, updatedAt fields
*/
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class=UuidGenerator::class)
* @SerializedName("id")
* @ApiProperty(identifier=true)
* @Assert\Uuid()
* @Groups({
* "SponsorshipRequest:output",
* "post_godchild_sponsorship_request",
* "get_godchilds_by_godfather_user",
* })
*/
private string $id;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="sponsorshipsRequest")
* @Groups({
* "SponsorshipRequest:io",
* "post_godchild_sponsorship_request",
* "get_godfather_by_godchild_email",
* "get_godchilds_by_godfather_user",
* })
* @Assert\NotBlank()
*/
private $user;
/**
* @ORM\Column(type="string", length=180)
* @SerializedName("email")
* @Assert\Email(normalizer="trim")
* @Groups({
* "SponsorshipRequest:io",
* "post_godchild_sponsorship_request",
* "get_godfather_by_godchild_email",
* "get_godchilds_by_godfather_user",
* })
* @Assert\NotBlank()
*/
private string $email;
/**
* @ORM\Column(type="string", length=2048, nullable=true)
* @Groups({
* "SponsorshipRequest:io",
* "post_godchild_sponsorship_request",
* "get_godfather_by_godchild_email",
* })
*/
private ?string $godsonMessage = null;
/**
* @var DateTime
*
* @ORM\Column(name="used_at", type="datetime", nullable=true)
* @Groups({
* "post_godchild_sponsorship_request",
* "get_godfather_by_godchild_email",
* "get_godchilds_by_godfather_user",
* })
*/
private $usedAt;
/**
* @ORM\Column(type="string", length=30)
* @Groups({
* "SponsorshipRequest:io",
* "post_godchild_sponsorship_request",
* "get_godfather_by_godchild_email",
* "get_godchilds_by_godfather_user",
* })
*/
private $status = self::STATUS_WAITING;
public function __construct()
{
$this->id = Uuid::uuid4();
}
public function getId(): string
{
return $this->id;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getEmail(): string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getGodsonMessage(): ?string
{
return $this->godsonMessage;
}
public function setGodsonMessage(string $godsonMessage): self
{
$this->godsonMessage = $godsonMessage;
return $this;
}
public function setUsedAt($usedAt)
{
$this->usedAt = $usedAt;
return $this;
}
public function getUsedAt()
{
return $this->usedAt;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
}