<?php

declare(strict_types=1);

namespace Autogedal\PromoRules\Model;

use Autogedal\PromoRules\Api\Data\RuleConfigInterface;
use Magento\Framework\Model\AbstractExtensibleModel;

/**
 * Promo-rule configuration model.
 */
class RuleConfig extends AbstractExtensibleModel implements RuleConfigInterface
{
    protected function _construct(): void
    {
        $this->_init(ResourceModel\RuleConfig::class);
    }

    public function getConfigId(): ?int
    {
        return $this->getData(self::CONFIG_ID) !== null ? (int) $this->getData(self::CONFIG_ID) : null;
    }

    public function setConfigId(?int $configId): RuleConfigInterface
    {
        return $this->setData(self::CONFIG_ID, $configId);
    }

    public function getRuleId(): ?int
    {
        return $this->getData(self::RULE_ID) !== null ? (int) $this->getData(self::RULE_ID) : null;
    }

    public function setRuleId(?int $ruleId): RuleConfigInterface
    {
        return $this->setData(self::RULE_ID, $ruleId);
    }

    public function getUsesPerEmail(): int
    {
        return (int) $this->getData(self::RESTRICT_ONCE_PER_EMAIL);
    }

    public function setUsesPerEmail(int $usesPerEmail): RuleConfigInterface
    {
        return $this->setData(self::RESTRICT_ONCE_PER_EMAIL, $usesPerEmail);
    }

    /**
     * Backward-compatible alias for the legacy field name.
     *
     * @return int
     */
    public function getRestrictOncePerEmail(): int
    {
        return $this->getUsesPerEmail();
    }

    /**
     * Backward-compatible alias for the legacy field name.
     *
     * @param int $restrictOncePerEmail
     * @return RuleConfigInterface
     */
    public function setRestrictOncePerEmail(int $restrictOncePerEmail): RuleConfigInterface
    {
        return $this->setUsesPerEmail($restrictOncePerEmail);
    }

    public function getBlockDiscountScope(): string
    {
        return (string) $this->getData(self::BLOCK_DISCOUNT_SCOPE);
    }

    public function setBlockDiscountScope(string $blockDiscountScope): RuleConfigInterface
    {
        return $this->setData(self::BLOCK_DISCOUNT_SCOPE, $blockDiscountScope);
    }

    public function getAdditionalPolicyFlags(): ?string
    {
        $value = $this->getData(self::ADDITIONAL_POLICY_FLAGS);
        return $value !== null ? (string) $value : null;
    }

    public function setAdditionalPolicyFlags(?string $additionalPolicyFlags): RuleConfigInterface
    {
        return $this->setData(self::ADDITIONAL_POLICY_FLAGS, $additionalPolicyFlags);
    }

    public function getCreatedAt(): ?string
    {
        $value = $this->getData(self::CREATED_AT);
        return $value !== null ? (string) $value : null;
    }

    public function setCreatedAt(?string $createdAt): RuleConfigInterface
    {
        return $this->setData(self::CREATED_AT, $createdAt);
    }

    public function getUpdatedAt(): ?string
    {
        $value = $this->getData(self::UPDATED_AT);
        return $value !== null ? (string) $value : null;
    }

    public function setUpdatedAt(?string $updatedAt): RuleConfigInterface
    {
        return $this->setData(self::UPDATED_AT, $updatedAt);
    }
}
