<?php

namespace App\Classes\Modules\Vouchers\DataTransferObjects;

use App\Classes\General\Interfaces\DataTransferObject;
use Carbon\Carbon;
use DateTime;
use Illuminate\Support\Facades\Log;

class VoucherObject implements DataTransferObject
{
    /** @var string */
    private $code;

    /** @var string|null */
    private $name;

    /** @var string|null */
    private $type;

    /** @var float|null */
    private $value;

    /** @var string|null */
    private $startDate;

    /** @var string|null */
    private $endDate;

    /**
     * VoucherObject constructor.
     * @param string $code
     * @param string $name
     * @param string $type
     * @param float $value
     * @param string $startDate
     * @param string $endDate
     */
    public function __construct(string $code, ?string $name, ?string $type, ?float $value, ?string $startDate = '', ?string $endDate = '')
    {
        $this->code = $code;
        $this->name = $name;
        $this->type = $type;
        $this->value = $value;
        $this->startDate = $startDate;
        $this->endDate = $endDate;
    }

    /**
     * @return string
     */
    public function getCode(): string
    {
        return $this->code;
    }

    /**
     * @return string
     */
    public function getName(): ?string
    {
        return $this->name;
    }


    /**
     * @return string
     */
    public function getType(): ?string
    {
        return $this->type;
    }


    /**
     * @return float
     */
    public function getValue(): ?float
    {
        return $this->value;
    }

    /**
     * @return DateTime
     */
    public function getStartDate(): ?DateTime
    {
        try {
            if(!$this->startDate) return null;
            // $dateTime = new DateTime($this->startDate);
            $dateTime = Carbon::parse($this->startDate)->tz('Asia/Kuala_Lumpur');
            return $dateTime;
        } catch (\Exception $e) {
            Log::error($e);
            return null;
        }
    }

    /**
     * @return DateTime
     */
    public function getEndDate(): ?DateTime
    {
        try {
            if(!$this->endDate) return null;
            $dateTime = Carbon::parse($this->endDate)->tz('Asia/Kuala_Lumpur');
            return $dateTime;
        } catch (\Exception $e) {
            Log::error($e);
            return null;
        }
    }
}
