<?php

namespace App\Entity;

use App\Enums\CaseLevel;
use App\Enums\County;
use App\Enums\Case\ReferralType;
use App\Repository\MemberCaseRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Types\UuidType;
use Symfony\Component\Uid\Uuid;

#[ORM\Entity(repositoryClass: MemberCaseRepository::class)]
class MemberCase
{
    #[ORM\Id]
    #[ORM\Column(type: UuidType::NAME, unique: true)]
    #[ORM\GeneratedValue(strategy: 'CUSTOM')]
    #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
    private ?Uuid $id = null;

    #[ORM\Column(length: 15)]
    private ?string $caseNumber = null;

    #[ORM\Column(length: 45)]
    private ?string $firstName = null;

    #[ORM\Column(length: 45)]
    private ?string $lastName = null;

    #[ORM\Column(length: 45)]
    private ?ReferralType $referralType = null;

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(nullable: false)]
    private ?ReferralSource $referralSource = null;

    #[ORM\ManyToOne]
    private ?ReferralSource $referralSource2 = null;

    #[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
    private ?\DateTimeInterface $admitDate = null;

    #[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
    private ?\DateTimeInterface $closeDate = null;

    #[ORM\Column(length: 15, nullable: true)]
    private ?string $dcsCaseId = null;

    #[ORM\Column(length: 45, nullable: true)]
    private ?string $insurance = null;

    #[ORM\Column(length: 45, nullable: true)]
    private ?string $medicaid = null;

    #[ORM\Column(length: 64, nullable: true)]
    private ?string $caseEmail = null;

    #[ORM\Column(length: 255, nullable: true)]
    private ?string $address = null;

    #[ORM\Column(length: 255, nullable: true)]
    private ?string $address2 = null;

    #[ORM\Column(length: 255, nullable: true)]
    private ?string $city = null;

    #[ORM\Column(length: 10, nullable: true)]
    private ?string $state = null;

    #[ORM\Column(nullable: true)]
    private ?int $zip = null;

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

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

    /**
     * @var Collection<int, UserCase>
     */
    #[ORM\OneToMany(targetEntity: UserCase::class, mappedBy: 'memberCase')]
    private Collection $userCases;

    /**
     * @var Collection<int, Referral>
     */
    #[ORM\OneToMany(targetEntity: Referral::class, mappedBy: 'memberCase', orphanRemoval: true)]
    private Collection $referrals;

    /**
     * @var Collection<int, MonthlyCaseNote>
     */
    #[ORM\OneToMany(targetEntity: MonthlyCaseNote::class, mappedBy: 'memberCase')]
    private Collection $monthlyCaseNotes;

    /**
     * @var Collection<int, Member>
     */
    #[ORM\OneToMany(targetEntity: Member::class, mappedBy: 'memberCase', orphanRemoval: true)]
    private Collection $members;

    /**
     * @var Collection<int, StaffNote>
     */
    #[ORM\OneToMany(targetEntity: StaffNote::class, mappedBy: 'memberCase')]
    private Collection $staffNotes;

    public function __construct()
    {
        $this->userCases = new ArrayCollection();
        $this->referrals = new ArrayCollection();
        $this->monthlyCaseNotes = new ArrayCollection();
        $this->members = new ArrayCollection();
        $this->staffNotes = new ArrayCollection();
    }

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

    public function getCaseNumber(): ?string
    {
        return $this->caseNumber;
    }

    public function setCaseNumber(string $caseNumber): static
    {
        $this->caseNumber = $caseNumber;

        return $this;
    }

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

    public function setFirstName(string $firstName): static
    {
        $this->firstName = $firstName;

        return $this;
    }

    public function getLastName(): ?string
    {
        return $this->lastName;
    }

    public function setLastName(string $lastName): static
    {
        $this->lastName = $lastName;

        return $this;
    }

    public function getCaseName(): string
    {
        return "{$this->lastName}, {$this->firstName}";
    }

    public function getReferralType(): ?ReferralType
    {
        return $this->referralType;
    }

    public function setReferralType(ReferralType $referralType): static
    {
        $this->referralType = $referralType;

        return $this;
    }

    public function getReferralSource(): ?ReferralSource
    {
        return $this->referralSource;
    }

    public function setReferralSource(?ReferralSource $referralSource): static
    {
        $this->referralSource = $referralSource;

        return $this;
    }

    public function getReferralSource2(): ?ReferralSource
    {
        return $this->referralSource2;
    }

    public function setReferralSource2(?ReferralSource $referralSource2): static
    {
        $this->referralSource2 = $referralSource2;

        return $this;
    }

    public function getAdmitDate(): ?\DateTimeInterface
    {
        return $this->admitDate;
    }

    public function setAdmitDate(?\DateTimeInterface $admitDate): static
    {
        $this->admitDate = $admitDate;

        return $this;
    }

    public function getCloseDate(): ?\DateTimeInterface
    {
        return $this->closeDate;
    }

    public function setCloseDate(?\DateTimeInterface $closeDate): static
    {
        $this->closeDate = $closeDate;

        return $this;
    }

    public function getDcsCaseId(): ?int
    {
        return $this->dcsCaseId;
    }

    public function setDcsCaseId(?int $dcsCaseId): static
    {
        $this->dcsCaseId = $dcsCaseId;

        return $this;
    }

    public function getInsurance(): ?string
    {
        return $this->insurance;
    }

    public function setInsurance(?string $insurance): static
    {
        $this->insurance = $insurance;

        return $this;
    }

    public function getMedicaid(): ?string
    {
        return $this->medicaid;
    }

    public function setMedicaid(?string $medicaid): static
    {
        $this->medicaid = $medicaid;

        return $this;
    }

    public function getCaseEmail(): ?string
    {
        return $this->caseEmail;
    }

    public function setCaseEmail(?string $caseEmail): static
    {
        $this->caseEmail = $caseEmail;

        return $this;
    }

    public function getAddress(): ?string
    {
        return $this->address;
    }

    public function setAddress(?string $address): static
    {
        $this->address = $address;

        return $this;
    }

    public function getCounty(): ?County
    {
        return $this->county;
    }

    public function setCounty(County $county): static
    {
        $this->county = $county;

        return $this;
    }

    public function getLevel(): ?CaseLevel
    {
        return $this->level;
    }

    public function setLevel(CaseLevel $level): static
    {
        $this->level = $level;

        return $this;
    }

    public function getAddress2(): ?string
    {
        return $this->address2;
    }

    public function setAddress2(?string $address2): static
    {
        $this->address2 = $address2;

        return $this;
    }

    public function getCity(): ?string
    {
        return $this->city;
    }

    public function setCity(?string $city): static
    {
        $this->city = $city;

        return $this;
    }

    public function getState(): ?string
    {
        return $this->state;
    }

    public function setState(?string $state): static
    {
        $this->state = $state;

        return $this;
    }

    public function getZip(): ?int
    {
        return $this->zip;
    }

    public function setZip(?int $zip): static
    {
        $this->zip = $zip;

        return $this;
    }

    /**
     * @return Collection<int, UserCase>
     */
    public function getUserCases(): Collection
    {
        return $this->userCases;
    }

    public function addUserCase(UserCase $userCase): static
    {
        if (!$this->userCases->contains($userCase)) {
            $this->userCases->add($userCase);
            $userCase->setMemberCase($this);
        }

        return $this;
    }

    public function removeUserCase(UserCase $userCase): static
    {
        if ($this->userCases->removeElement($userCase)) {
            // set the owning side to null (unless already changed)
            if ($userCase->getMemberCase() === $this) {
                $userCase->setMemberCase(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, Referral>
     */
    public function getReferrals(): Collection
    {
        return $this->referrals;
    }

    public function addReferral(Referral $referral): static
    {
        if (!$this->referrals->contains($referral)) {
            $this->referrals->add($referral);
            $referral->setMemberCase($this);
        }

        return $this;
    }

    public function removeReferral(Referral $referral): static
    {
        if ($this->referrals->removeElement($referral)) {
            // set the owning side to null (unless already changed)
            if ($referral->getMemberCase() === $this) {
                $referral->setMemberCase(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, MonthlyCaseNote>
     */
    public function getMonthlyCaseNotes(): Collection
    {
        return $this->monthlyCaseNotes;
    }

    public function addMonthlyCaseNote(MonthlyCaseNote $monthlyCaseNote): static
    {
        if (!$this->monthlyCaseNotes->contains($monthlyCaseNote)) {
            $this->monthlyCaseNotes->add($monthlyCaseNote);
            $monthlyCaseNote->setMemberCase($this);
        }

        return $this;
    }

    public function removeMonthlyCaseNote(MonthlyCaseNote $monthlyCaseNote): static
    {
        if ($this->monthlyCaseNotes->removeElement($monthlyCaseNote)) {
            // set the owning side to null (unless already changed)
            if ($monthlyCaseNote->getMemberCase() === $this) {
                $monthlyCaseNote->setMemberCase(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, Member>
     */
    public function getMembers(): Collection
    {
        return $this->members;
    }

    public function addMember(Member $member): static
    {
        if (!$this->members->contains($member)) {
            $this->members->add($member);
            $member->setCaseId($this);
        }

        return $this;
    }

    public function removeMember(Member $member): static
    {
        if ($this->members->removeElement($member)) {
            // set the owning side to null (unless already changed)
            if ($member->getCaseId() === $this) {
                $member->setCaseId(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection<int, StaffNote>
     */
    public function getStaffNotes(): Collection
    {
        return $this->staffNotes;
    }

    public function addStaffNote(StaffNote $staffNote): static
    {
        if (!$this->staffNotes->contains($staffNote)) {
            $this->staffNotes->add($staffNote);
            $staffNote->setMemberCase($this);
        }

        return $this;
    }

    public function removeStaffNote(StaffNote $staffNote): static
    {
        if ($this->staffNotes->removeElement($staffNote)) {
            // set the owning side to null (unless already changed)
            if ($staffNote->getMemberCase() === $this) {
                $staffNote->setMemberCase(null);
            }
        }

        return $this;
    }
}
