<?php

declare(strict_types=1);

/*
 * This file is part of the Ferienpass package.
 *
 * (c) Richard Henkenjohann <richard@ferienpass.online>
 *
 * For more information visit the project website <https://ferienpass.online>
 * or the documentation under <https://docs.ferienpass.online>.
 */

namespace Ferienpass\CoreBundle\Settings;

use Symfony\Component\DependencyInjection\Attribute\Autowire;

class SystemSettingsManager
{
    public function __construct(
        private readonly PageConfigManager $pageConfigManager,
        #[Autowire(param: 'ferienpass.friends_booking')]
        private readonly ?bool $friendsBookingConfig = null,
        #[Autowire(param: 'ferienpass.preferred_postal_codes')]
        private readonly ?array $preferredPostalCodesConfig = null,
        #[Autowire(param: 'ferienpass.require_postal_address')]
        private readonly ?bool $requirePostalAddressConfig = null,
        #[Autowire(param: 'ferienpass.erase_data_period')]
        private readonly ?string $eraseDataPeriodConfig = null,
        #[Autowire(param: 'ferienpass.attendance_remind_period')]
        private readonly ?string $attendanceRemindPeriodConfig = null,
        #[Autowire(param: 'ferienpass.payment_allow_select')]
        private readonly ?bool $paymentAllowSelectConfig = null,
        #[Autowire(param: 'ferienpass.age_tolerance')]
        private readonly ?string $ageToleranceConfig = null,
        #[Autowire(param: 'ferienpass.withdraw_grace_period')]
        private readonly ?string $withdrawGracePeriodConfig = null,
        #[Autowire(param: 'ferienpass.no_withdraw_after_grace_period')]
        private readonly ?bool $noWithdrawAfterGracePeriodConfig = null,
        #[Autowire(param: 'ferienpass.no_withdraw_after_application_deadline')]
        private readonly ?bool $noWithdrawAfterApplicationDeadlineConfig = null,
        #[Autowire(param: 'ferienpass.receipt_number_prefix')]
        private readonly ?string $receiptNumberPrefixConfig = null,
        #[Autowire(param: 'ferienpass.remind_attendance')]
        private readonly ?bool $remindAttendanceConfig = null,
    ) {
    }

    public function isFriendsBookingFromConfig(): bool
    {
        return null !== $this->friendsBookingConfig;
    }

    public function isPreferredPostalCodesFromConfig(): bool
    {
        return null !== $this->preferredPostalCodesConfig;
    }

    public function isRequirePostalAddressFromConfig(): bool
    {
        return null !== $this->requirePostalAddressConfig;
    }

    public function isEraseDataPeriodFromConfig(): bool
    {
        return null !== $this->eraseDataPeriodConfig;
    }

    public function isAttendanceRemindPeriodFromConfig(): bool
    {
        return null !== $this->attendanceRemindPeriodConfig;
    }

    public function isPaymentAllowSelectFromConfig(): bool
    {
        return null !== $this->paymentAllowSelectConfig;
    }

    public function isAgeToleranceFromConfig(): bool
    {
        return null !== $this->ageToleranceConfig;
    }

    public function isWithdrawGracePeriodFromConfig(): bool
    {
        return null !== $this->withdrawGracePeriodConfig;
    }

    public function isNoWithdrawAfterGracePeriodFromConfig(): bool
    {
        return null !== $this->noWithdrawAfterGracePeriodConfig;
    }

    public function isNoWithdrawAfterApplicationDeadlineFromConfig(): bool
    {
        return null !== $this->noWithdrawAfterApplicationDeadlineConfig;
    }

    public function isReceiptNumberPrefixFromConfig(): bool
    {
        return null !== $this->receiptNumberPrefixConfig;
    }

    public function isRemindAttendanceFromConfig(): bool
    {
        return null !== $this->remindAttendanceConfig;
    }

    public function isFriendsBooking(): bool
    {
        return $this->friendsBookingConfig ?? $this->pageConfigManager->getPageConfig()->isFriendsBooking();
    }

    public function getPreferredPostalCodes(): ?string
    {
        if ($this->isPreferredPostalCodesFromConfig()) {
            return implode(',', $this->preferredPostalCodesConfig);
        }

        return $this->pageConfigManager->getPageConfig()->getPreferredPostalCodes();
    }

    public function getPreferredPostalCodesArray(): array
    {
        if ($this->isPreferredPostalCodesFromConfig()) {
            return $this->preferredPostalCodesConfig;
        }

        return $this->pageConfigManager->getPageConfig()->getPreferredPostalCodesArray();
    }

    public function isRequirePostalAddress(): bool
    {
        return $this->requirePostalAddressConfig ?? $this->pageConfigManager->getPageConfig()->isRequirePostalAddress();
    }

    public function getEraseDataPeriod(): ?string
    {
        return $this->eraseDataPeriodConfig ?? $this->pageConfigManager->getPageConfig()->getEraseDataPeriod();
    }

    public function getAttendanceRemindPeriod(): ?string
    {
        return $this->attendanceRemindPeriodConfig ?? $this->pageConfigManager->getPageConfig()->getAttendanceRemindPeriod();
    }

    public function isPaymentAllowSelect(): bool
    {
        return $this->paymentAllowSelectConfig ?? $this->pageConfigManager->getPageConfig()->isPaymentAllowSelect();
    }

    public function getAgeTolerance(): ?string
    {
        return $this->ageToleranceConfig ?? $this->pageConfigManager->getPageConfig()->getAgeTolerance();
    }

    public function getWithdrawGracePeriod(): ?string
    {
        return $this->withdrawGracePeriodConfig ?? $this->pageConfigManager->getPageConfig()->getWithdrawGracePeriod();
    }

    public function isNoWithdrawAfterGracePeriod(): bool
    {
        return $this->noWithdrawAfterGracePeriodConfig ?? $this->pageConfigManager->getPageConfig()->isNoWithdrawAfterGracePeriod();
    }

    public function isNoWithdrawAfterApplicationDeadline(): bool
    {
        return $this->noWithdrawAfterApplicationDeadlineConfig ?? $this->pageConfigManager->getPageConfig()->isNoWithdrawAfterApplicationDeadline();
    }

    public function getReceiptNumberPrefix(): ?string
    {
        return $this->receiptNumberPrefixConfig ?? $this->pageConfigManager->getPageConfig()->getReceiptNumberPrefix();
    }

    public function isRemindAttendance(): bool
    {
        return $this->remindAttendanceConfig ?? $this->pageConfigManager->getPageConfig()->isRemindAttendance();
    }
}
