<?php

namespace App\Entity;

use App\Repository\ChildRepository;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: ChildRepository::class)]
#[ORM\Table(name: 'children')]
#[ORM\Index(name: 'idx_child_family_active', columns: ['family_id', 'active'])]
class Child
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(nullable: false, onDelete: 'RESTRICT')]
    private Family $family;

    #[ORM\Column(length: 80)]
    private string $firstName;

    #[ORM\Column(options: ['default' => true])]
    private bool $active = true;

    #[ORM\Column(options: ['default' => 0])]
    private int $displayOrder = 0;

    #[ORM\Column]
    private \DateTimeImmutable $createdAt;

    public function __construct(Family $family, string $firstName, int $displayOrder = 0)
    {
        $this->family = $family;
        $this->firstName = trim($firstName);
        $this->displayOrder = $displayOrder;
        $this->createdAt = new \DateTimeImmutable();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getFamily(): Family
    {
        return $this->family;
    }

    public function getFirstName(): string
    {
        return $this->firstName;
    }

    public function isActive(): bool
    {
        return $this->active;
    }

    public function getDisplayOrder(): int
    {
        return $this->displayOrder;
    }
}
