<?php
declare(strict_types=1);

namespace Autogedal\BlackFriday\Model\Config\Backend;

use Magento\Framework\Exception\LocalizedException;

class DateTime extends TeaserCacheCleaning
{
    public function beforeSave()
    {
        $value = trim((string)$this->getValue());
        $date = \DateTimeImmutable::createFromFormat('Y-m-d H:i', $value);
        if (!$date || $date->format('Y-m-d H:i') !== $value) {
            throw new LocalizedException(__('Data "%1" nu este valida. Formatul corect este AAAA-LL-ZZ HH:MM, de exemplu 2026-11-06 00:00.', $value));
        }
        $this->setValue($value);
        return parent::beforeSave();
    }
}
