src/DB/Entity/User/Notifications/RemixNotification.php
<?php

declare(strict_types=1);

namespace App\DB\Entity\User\Notifications;

use App\DB\Entity\Project\Program;
use App\DB\Entity\User\User;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class RemixNotification extends CatroNotification
{
  /*
   *  You have to set this parameter otherwise the wrong template will be rendered.
   */
  private string $twig_template = '/User/Notification/Type/Remix.html.twig';

  /**
   * RemixNotification constructor.
   *
   * @param User         $user          the User to which this RemixNotification will be shown
   * @param User|null    $remix_from    the owner of the parent Program
   * @param Program|null $program       the parent Program
   * @param Program|null $remix_program the newly remixed child Program
   */
  public function __construct(
    User $user,
    #[ORM\JoinColumn(name: 'remix_root', referencedColumnName: 'id', nullable: true)]
    #[ORM\ManyToOne(targetEntity: User::class)]
    private ?User $remix_from,
    #[ORM\JoinColumn(name: 'program_id', referencedColumnName: 'id', nullable: true)]
    #[ORM\ManyToOne(targetEntity: Program::class, inversedBy: 'remix_notification_mentions_as_parent')]
    private ?Program $program,
    #[ORM\JoinColumn(name: 'remix_program_id', referencedColumnName: 'id', nullable: true)]
    #[ORM\ManyToOne(targetEntity: Program::class, inversedBy: 'remix_notification_mentions_as_child')]
    private ?Program $remix_program,
  ) {
    parent::__construct($user, '', '', 'remix');
  }

  /**
   * Returns the owner of the parent Program.
   */
  public function getRemixFrom(): ?User
  {
    return $this->remix_from;
  }

  /**
   * Sets the owner of the parent Program.
   */
  public function setRemixFrom(?User $remix_from): void
  {
    $this->remix_from = $remix_from;
  }

  /**
   * It's important to overwrite the get method, otherwise it won't work
   * and the wrong template will be rendered.
   */
  #[\Override]
  public function getTwigTemplate(): string
  {
    return $this->twig_template;
  }

  /**
   * Returns the parent Program.
   */
  public function getProgram(): ?Program
  {
    return $this->program;
  }

  /**
   * Sets the parent Program.
   */
  public function setProgram(?Program $program): void
  {
    $this->program = $program;
  }

  /**
   * Returns the child Program.
   */
  public function getRemixProgram(): ?Program
  {
    return $this->remix_program;
  }

  /**
   * Sets the child Program.
   */
  public function setRemixProgram(?Program $remix_program): void
  {
    $this->remix_program = $remix_program;
  }
}
