<?php

namespace CouponsPlus\App\Plugin;

use Carbon\Carbon;
use CouponsPlus\App\Time\WpDateTimeZone;
use CouponsPlus\Original\Characters\StringManager;
use JsonSerializable;

class InstalledVersion implements JsonSerializable
{
    CONST DATE_FORMAT = 'Y-m-d';

    protected $version;
    protected $dateSource;
    protected $date;
    
    public function __construct(string $version, string $date)
    {
        $this->version = $version;
        $this->dateSource = $date;
    } 

    public function getVersion() : StringManager
    {
        return new StringManager($this->version);
    }

    public function getDate() : Carbon
    {
        return new Carbon($this->dateSource, WpDateTimeZone::getWpTimezone());
    }

    #[\ReturnTypeWillChange]
    public function jsonSerialize()
    {
        return [$this->version, $this->getDate()->format(static::DATE_FORMAT)];
    }  
}