<?php

declare(strict_types=1);

/*
 * This file is part of the Ferienpass package.
 *
 * (c) Richard Henkenjohann <richard@ferienpass.online>
 *
 * For more information visit the project website <https://ferienpass.online>
 * or the documentation under <https://docs.ferienpass.online>.
 */

namespace Ferienpass\CoreBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * The `tenant_id` mapping behind {@see TenantAwareInterface}.
 *
 * The column is nullable on purpose: single-tenant builds never enable
 * multi-tenancy, so every row keeps a null tenant and nothing about their
 * schema or queries changes. Doctrine indexes the foreign key column for us.
 *
 * `onDelete: RESTRICT` is a deliberate safety net — deleting a tenant must
 * never silently cascade away a municipality's children, participants and
 * receipts. The admin UI refuses to delete a tenant that still owns data.
 */
trait TenantAwareTrait
{
    #[ORM\ManyToOne(targetEntity: Tenant::class)]
    #[ORM\JoinColumn(name: 'tenant_id', referencedColumnName: 'id', nullable: true, onDelete: 'RESTRICT')]
    private ?Tenant $tenant = null;

    public function getTenant(): ?Tenant
    {
        return $this->tenant;
    }

    public function setTenant(?Tenant $tenant): void
    {
        $this->tenant = $tenant;
    }
}
