<?php

namespace App\Entity;

use App\Enums\ReferralServiceType;
use App\Repository\StandardNoteRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;

#[ORM\Entity(repositoryClass: StandardNoteRepository::class)]
class StandardNote extends Note implements JsonSerializable
{
    #[ORM\Column(type: Types::TEXT, nullable: true)]
    private ?string $note = null;

    public function getNote(): ?string
    {
        return $this->note;
    }

    public function setNote(?string $note): static
    {
        $this->note = $note;

        return $this;
    }

    public function jsonSerialize(): array
    {
        $members = [];
        foreach ($this->getMembers() as $member) {
            /** @var Member $member */
            $members[] = $member->getName();
        }
        return [
            'id' => $this->getId()->toString(),
            'date' => $this->getDate()->format('M j, Y'),
            'startTime' => $this->getStartTime()->format('g:i a'),
            'endTime' => $this->getEndTime()->format('g:i a'),
            'serviceCode' => $this->getReferral()->getServiceCode()->value,
            'noteType' => ($this->getReferral()->getServiceCode() == ReferralServiceType::VS_THBB ? 'visit' : 'standard'),
            'status' => $this->getStatus()->value,
            'location' => $this->getLocation()->value,
            'method' => ucwords(str_replace('_', ' ', strtolower($this->getMethod()->name))),
            'members' => implode(', ', $members),
            'duration' => $this->calcTimeUsed(),
        ];
    }
}
