<?php

declare(strict_types=1);

namespace App\Library\VK\Entity;

use Carbon\Carbon;

class VkPost
{
    private int $id;
    private string $source_name;
    private bool $post = true;
    private string $text;
    private int $from_id;
    private int $owner_id;
    private array $attachments = [];
    private Carbon $date;

    public function toArray(): array
    {
        return [
            'id' => $this->id,
            'post' => $this->post ? "post" : "copy",
            'text' => $this->text,
            'from_id' => $this->from_id,
            'owner_id' => $this->owner_id,
            'date' => $this->getDate()->toIso8601String(),
            'name' => $this->getSourceName(),
            'attachments' => $this->attachments,
        ];
    }

    public function isEmpty(): bool
    {
        return empty($this->text);
    }

    public function isPost(): bool
    {
        return $this->post;
    }

    public function isRepost(): bool
    {
        return ! $this->post;
    }

    public function setIsPost(): void
    {
        $this->post = true;
    }

    public function setIsRepost(): void
    {
        $this->post = false;
    }

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

    public function getText(): string
    {
        return $this->text;
    }

    public function getFromId(): int
    {
        return $this->from_id;
    }

    public function getDate(): Carbon
    {
        return $this->date;
    }

    /**
     * @return string
     */
    public function getOwnerId(): int
    {
        return $this->owner_id;
    }

    public function getSourceName(): string
    {
        return $this->source_name;
    }

    public function setId(int $id): void
    {
        $this->id = $id;
    }

    public function setText(string $text): void
    {
        $this->text = $text;
    }

    public function setFromId(int $from_id): void
    {
        $this->from_id = $from_id;
    }

    public function setDate(string|int $date): void
    {
        $this->date = Carbon::parse($date);
    }

    public function setOwnerId(int $owner_id): void
    {
        $this->owner_id = $owner_id;
    }

    public function setAttachments(array $attachments = []): void
    {
        $this->attachments = $attachments;
    }

    public function setSourceName(string $source_name): void
    {
        $this->source_name = $source_name;
    }
}
