<?php
namespace App\Entity;
use App\Repository\ShopFollowRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: ShopFollowRepository::class)]
#[ORM\Table(name: 'shop_follows')]
#[ORM\UniqueConstraint(name: 'unique_user_shop_follow', columns: ['user_id', 'shop_id'])]
class ShopFollow
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
private ?User $user = null;
#[ORM\ManyToOne(targetEntity: Shop::class, inversedBy: 'follows')]
#[ORM\JoinColumn(name: 'shop_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
private ?Shop $shop = null;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
private ?\DateTimeImmutable $followedAt = null;
#[ORM\Column(type: Types::BOOLEAN, options: ['default' => true])]
private bool $isActive = true;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
private ?\DateTimeImmutable $unfollowedAt = null;
public function __construct()
{
$this->followedAt = new \DateTimeImmutable();
}
public function getId(): ?int
{
return $this->id;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): static
{
$this->user = $user;
return $this;
}
public function getShop(): ?Shop
{
return $this->shop;
}
public function setShop(?Shop $shop): static
{
$this->shop = $shop;
return $this;
}
public function getFollowedAt(): ?\DateTimeImmutable
{
return $this->followedAt;
}
public function setFollowedAt(\DateTimeImmutable $followedAt): static
{
$this->followedAt = $followedAt;
return $this;
}
public function isActive(): bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): static
{
$this->isActive = $isActive;
return $this;
}
public function getUnfollowedAt(): ?\DateTimeImmutable
{
return $this->unfollowedAt;
}
public function setUnfollowedAt(?\DateTimeImmutable $unfollowedAt): static
{
$this->unfollowedAt = $unfollowedAt;
return $this;
}
public function unfollow(): static
{
$this->isActive = false;
$this->unfollowedAt = new \DateTimeImmutable();
return $this;
}
public function refollow(): static
{
$this->isActive = true;
$this->unfollowedAt = null;
return $this;
}
}