<?php

namespace App\Entity;

use App\Repository\PriceListRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass=PriceListRepository::class)
 * @ORM\Entity(readOnly=true)
 * @ORM\Table(name="price_list_view")
 */
class PriceList
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $kodoper;

    /**
     * @ORM\Column(type="text", nullable=true)
     */
    private $schname;

    /**
     * @ORM\Column(type="text", nullable=true)
     */
    private $specname;

    /**
     * @ORM\Column(type="bigint", nullable=true)
     */
    private $speccode;

    /**
     * @ORM\Column(type="json", nullable=true)
     */
    private $priceInfo = [];

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $discpercent;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $discprice;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $structname;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $fname;

    /**
     * @ORM\Column(type="integer", nullable=true)
     */
    private $filial;

    /**
     * @ORM\Column(type="text", nullable=true)
     */
    private $comment;

    /**
     * @ORM\Column(type="integer", nullable=true)
     */
    private $mediaId;

    /**
     * @ORM\Column(type="datetime")
     */
    private $dateUpdate;

    /**
     * @ORM\Column(type="integer", nullable=true)
     */
    private $groupId;

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

    public function getKodoper(): ?string
    {
        return $this->kodoper;
    }

    public function getSchname(): ?string
    {
        return $this->schname;
    }

    public function getSpecname(): ?string
    {
        return $this->specname;
    }

    public function getSpeccode(): ?string
    {
        return $this->speccode;
    }

    public function getPriceInfo(): ?array
    {
        return $this->priceInfo;
    }

    public function getDiscpercent(): ?string
    {
        return $this->discpercent;
    }

    public function getDiscprice(): ?string
    {
        return $this->discprice;
    }

    public function getStructname(): ?string
    {
        return $this->structname;
    }

    public function getFname(): ?string
    {
        return $this->fname;
    }

    public function getFilial(): ?int
    {
        return $this->filial;
    }

    public function getComment(): ?string
    {
        return $this->comment;
    }

    public function getMediaId(): ?int
    {
        return $this->mediaId;
    }

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

    public function getGroupId(): ?int
    {
        return $this->groupId;
    }

    public function getActive(): bool
    {
        if ($this->dateUpdate === null) {
            return false;
        }
        
        $twoDaysAgo = (new \DateTime())->modify('-2 days');
        
        return $this->dateUpdate >= $twoDaysAgo;
    }

    public function setKodoper(?string $kodoper): static
    {
        $this->kodoper = $kodoper;

        return $this;
    }

    public function setSchname(?string $schname): static
    {
        $this->schname = $schname;

        return $this;
    }

    public function setSpecname(?string $specname): static
    {
        $this->specname = $specname;

        return $this;
    }

    public function setSpeccode(?string $speccode): static
    {
        $this->speccode = $speccode;

        return $this;
    }

    public function setPriceInfo(?array $priceInfo): static
    {
        $this->priceInfo = $priceInfo;

        return $this;
    }

    public function setDiscpercent(?string $discpercent): static
    {
        $this->discpercent = $discpercent;

        return $this;
    }

    public function setDiscprice(?string $discprice): static
    {
        $this->discprice = $discprice;

        return $this;
    }

    public function setStructname(?string $structname): static
    {
        $this->structname = $structname;

        return $this;
    }

    public function setFname(?string $fname): static
    {
        $this->fname = $fname;

        return $this;
    }

    public function setFilial(?int $filial): static
    {
        $this->filial = $filial;

        return $this;
    }

    public function setComment(?string $comment): static
    {
        $this->comment = $comment;

        return $this;
    }

    public function setMediaId(?int $mediaId): static
    {
        $this->mediaId = $mediaId;

        return $this;
    }

    public function setDateUpdate(\DateTimeInterface $dateUpdate): static
    {
        $this->dateUpdate = $dateUpdate;

        return $this;
    }

    public function setGroupId(?int $groupId): static
    {
        $this->groupId = $groupId;

        return $this;
    }

    public function toArray(): array
    {
        return [
            'kodoper' => $this->getKodoper(),
            'schname' => $this->getSchname(),
            'specname' => $this->getSpecname(),
            'speccode' => $this->getSpeccode(),
            'priceInfo' => $this->getPriceInfo(),
            'discpercent' => $this->getDiscpercent(),
            'discprice' => $this->getDiscprice(),
            'structname' => $this->getStructname(),
            'fname' => $this->getFname(),
            'filial' => $this->getFilial(),
            'comment' => $this->getComment(),
            'mediaId' => $this->getMediaId(),
            'dateUpdate' => $this->getDateUpdate() ? $this->getDateUpdate()->format('Y-m-d H:i:s') : null,
            'groupId' => $this->getGroupId(),
            'active' => $this->getActive()
        ];
    }
}
