<?php

namespace App\Entity;

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

#[ORM\Entity(repositoryClass: VisitNoteRepository::class)]
class VisitNote extends Note implements JsonSerializable
{
    #[ORM\Column(type: Types::TEXT)]
    private ?string $narrative = null;

    #[ORM\Column(type: Types::TEXT)]
    private ?string $strengths = null;

    #[ORM\Column(type: Types::TEXT)]
    private ?string $issues = null;

    #[ORM\Column(type: Types::TEXT)]
    private ?string $recommendation = null;

    #[ORM\Column(enumType: VisitQualityLevel::class)]
    private ?VisitQualityLevel $parentalRole = null;

    #[ORM\Column(enumType: VisitQualityLevel::class)]
    private ?VisitQualityLevel $childDevelopment = null;

    #[ORM\Column(enumType: VisitQualityLevel::class)]
    private ?VisitQualityLevel $appropriateResponse = null;

    #[ORM\Column(enumType: VisitQualityLevel::class)]
    private ?VisitQualityLevel $childAheadOfSelf = null;

    #[ORM\Column(enumType: VisitQualityLevel::class)]
    private ?VisitQualityLevel $showsEmpathy = null;

    #[ORM\Column(enumType: VisitQualityLevel::class)]
    private ?VisitQualityLevel $childFocused = null;

    public function getNarrative(): ?string
    {
        return $this->narrative;
    }

    public function setNarrative(string $narrative): static
    {
        $this->narrative = $narrative;

        return $this;
    }

    public function getStrengths(): ?string
    {
        return $this->strengths;
    }

    public function setStrengths(string $strengths): static
    {
        $this->strengths = $strengths;

        return $this;
    }

    public function getIssues(): ?string
    {
        return $this->issues;
    }

    public function setIssues(string $issues): static
    {
        $this->issues = $issues;

        return $this;
    }

    public function getRecommendation(): ?string
    {
        return $this->recommendation;
    }

    public function setRecommendation(string $recommendation): static
    {
        $this->recommendation = $recommendation;

        return $this;
    }

    public function getParentalRole(): ?VisitQualityLevel
    {
        return $this->parentalRole;
    }

    public function setParentalRole(VisitQualityLevel $parentalRole): static
    {
        $this->parentalRole = $parentalRole;

        return $this;
    }

    public function getChildDevelopment(): ?VisitQualityLevel
    {
        return $this->childDevelopment;
    }

    public function setChildDevelopment(VisitQualityLevel $childDevelopment): static
    {
        $this->childDevelopment = $childDevelopment;

        return $this;
    }

    public function getAppropriateResponse(): ?VisitQualityLevel
    {
        return $this->appropriateResponse;
    }

    public function setAppropriateResponse(VisitQualityLevel $appropriateResponse): static
    {
        $this->appropriateResponse = $appropriateResponse;

        return $this;
    }

    public function getChildAheadOfSelf(): ?VisitQualityLevel
    {
        return $this->childAheadOfSelf;
    }

    public function setChildAheadOfSelf(VisitQualityLevel $childAheadOfSelf): static
    {
        $this->childAheadOfSelf = $childAheadOfSelf;

        return $this;
    }

    public function getShowsEmpathy(): ?VisitQualityLevel
    {
        return $this->showsEmpathy;
    }

    public function setShowsEmpathy(VisitQualityLevel $showsEmpathy): static
    {
        $this->showsEmpathy = $showsEmpathy;

        return $this;
    }

    public function getChildFocused(): ?VisitQualityLevel
    {
        return $this->childFocused;
    }

    public function setChildFocused(VisitQualityLevel $childFocused): static
    {
        $this->childFocused = $childFocused;

        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))),
            'narrative' => $this->getNarrative(),
            'strengths' => $this->getStrengths(),
            'issues' => $this->getIssues(),
            'recommendation' => $this->getRecommendation(),
            'parentalRole' => $this->getParentalRole(),
            'childDevelopment' => $this->getChildDevelopment(),
            'appropriateResponse' => $this->getAppropriateResponse(),
            'childAheadOfSelf' => $this->getChildAheadOfSelf(),
            'showsEmpathy' => $this->getShowsEmpathy(),
            'childFocused' => $this->getChildFocused(),
            'members' => implode(', ', $members),
            'duration' => $this->calcTimeUsed(),
        ];
    }
}
