<?php
/**
 * BookiFlex
 *
 * @package   BookiFlex
 * @author    BookiFlex
 * @copyright Copyright (c) 2025 BookiFlex
 * @license   GPL-2.0-or-later
 *
 * @link      https://bookiflex.com
 */


declare(strict_types=1);
namespace BookiFlex\Plugin\Admin\Lifecycle\DefaultSettings;

use BookiFlex\Core\Admin\Settings\SettingsManager;
use BookiFlex\Extensions\Notification\Admin\NotificationSettings;

defined( 'ABSPATH' ) || exit;

class DefaultSettings
{
    private function __construct()
    {
        $this->baseSettings();
        $this->notificationSettings();
    }

    public static function create(): self
    {
        return new self();
    }

    private function baseSettings(): void
    {
        // General
        carbon_set_theme_option(SettingsManager::DEFAULT_CURRENCY, 'USD', '', true);
        carbon_set_theme_option(SettingsManager::CHECK_IN_TIME, '14:00', '', true);
        carbon_set_theme_option(SettingsManager::CHECK_OUT_TIME, '12:00', '', true);
        carbon_set_theme_option(SettingsManager::AUTO_CONFIRMATION_FOR_NON_PAYABLE_PAYMENT_TYPES, false);
        carbon_set_theme_option(SettingsManager::AUTO_CONFIRMATION_AFTER_PAYMENT_IS_PAID, 'yes');

        // Contact info
        carbon_set_theme_option(SettingsManager::NAME, 'Example Apartments');
        carbon_set_theme_option(SettingsManager::ADDRESS, '12 Example Street, Test City');
        carbon_set_theme_option(SettingsManager::PHONE, '+1 555 234 5678');
        carbon_set_theme_option(SettingsManager::EMAIL, $this->getEmail());
        carbon_set_theme_option(SettingsManager::LONGITUDE, '');
        carbon_set_theme_option(SettingsManager::LATITUDE, '');

        // Payment
        carbon_set_theme_option(SettingsManager::BANK_ACCOUNT, $this->getBankAccount());

        carbon_set_theme_option(SettingsManager::RULES_OF_LIVING, [
            ['text' => __('Quiet hours are from 10:00 PM to 6:00 AM.', 'bookiflex')],
            ['text' => __('No smoking inside the property.', 'bookiflex')],
            ['text' => __('Pets allowed upon request.', 'bookiflex')],
        ]);

        carbon_set_theme_option(SettingsManager::BOOKING_BUTTON_ACTIVE, false);
        carbon_set_theme_option(SettingsManager::BOOKING_BUTTON_TEXT, __('Book now', 'bookiflex'));
        carbon_set_theme_option(SettingsManager::BOOKING_BUTTON_COLOR, '#28A745');
        carbon_set_theme_option(SettingsManager::BOOKING_BUTTON_PULSE, false);
    }

    private function notificationSettings(): void
    {
        carbon_set_theme_option(NotificationSettings::MAIL_SIGNATURE, $this->getSignature());
        carbon_set_theme_option(NotificationSettings::MAIL_FROM_EMAIL, $this->getEmail());
        carbon_set_theme_option(NotificationSettings::MAIL_FROM_NAME, __('John Doe', 'bookiflex'));

        carbon_set_theme_option(NotificationSettings::CUSTOMER_NEW_ACTIVE, true);
        carbon_set_theme_option(NotificationSettings::CUSTOMER_NEW_SUBJECT, __('Thank you for your reservation #{{number}}', 'bookiflex'));

        carbon_set_theme_option(NotificationSettings::CUSTOMER_OVERDUE_ACTIVE, true);
        carbon_set_theme_option(NotificationSettings::CUSTOMER_OVERDUE_SUBJECT, __('Action required for reservation #{{number}}', 'bookiflex'));

        carbon_set_theme_option(NotificationSettings::CUSTOMER_CONFIRMED_ACTIVE, true);
        carbon_set_theme_option(NotificationSettings::CUSTOMER_CONFIRMED_SUBJECT, __('Reservation #{{number}} confirmed', 'bookiflex'));

        carbon_set_theme_option(NotificationSettings::CUSTOMER_CANCELLED_ACTIVE, true);
        carbon_set_theme_option(NotificationSettings::CUSTOMER_CANCELLED_SUBJECT, __('{{firstName}}, your reservation #{{number}} was cancelled', 'bookiflex'));

        carbon_set_theme_option(NotificationSettings::MANAGER_NEW_ACTIVE, true);
        carbon_set_theme_option(NotificationSettings::MANAGER_NEW_SUBJECT, __('New reservation #{{number}}', 'bookiflex'));

        carbon_set_theme_option(NotificationSettings::MANAGER_OVERDUE_ACTIVE, true);
        carbon_set_theme_option(NotificationSettings::MANAGER_OVERDUE_SUBJECT, __('Reservation #{{number}} is overdue', 'bookiflex'));

        carbon_set_theme_option(NotificationSettings::MANAGER_CANCELLED_ACTIVE, true);
        carbon_set_theme_option(NotificationSettings::MANAGER_CANCELLED_SUBJECT, __('Reservation #{{number}} has been cancelled', 'bookiflex'));

        carbon_set_theme_option(NotificationSettings::MANAGER_WAITING_CONFIRMATION_ACTIVE, true);
        carbon_set_theme_option(NotificationSettings::MANAGER_WAITING_CONFIRMATION_SUBJECT, __('Reservation awaiting confirmation: #{{number}}', 'bookiflex'));
    }

    private function getBankAccount(): string
    {
        return '
<strong>' . __('Bank Name:', 'bookiflex') . '</strong> Example Bank<br>
<strong>' . __('Account Holder:', 'bookiflex') . '</strong> Alex Example<br>
<strong>' . __('IBAN:', 'bookiflex') . '</strong> US00 0000 0000 0000 0000 00<br>
<strong>' . __('SWIFT/BIC:', 'bookiflex') . '</strong> EXAMPLEDXXX<br>
<strong>' . __('Bank Address:', 'bookiflex') . '</strong> 12 Example Street, Test City<br>
<strong>' . __('Account Number:', 'bookiflex') . '</strong> 0532013000<br>
<strong>' . __('Routing Number:', 'bookiflex') . '</strong> 37040044<br>
<strong>' . __('Currency:', 'bookiflex') . '</strong> {{currency}}<br>
<strong>' . __('Reference Note:', 'bookiflex') . '</strong> Reservation #{{reservation.number}}
';
    }

    private function getSignature(): string
    {
        return sprintf('<p>%s</p><p>%s</p>',
            __('If you have any questions about this receipt, simply reply to this email or reach out to our support team for help.', 'bookiflex'),
            __('Cheers, <br>The PropertyName team', 'bookiflex')
        );
    }

    private function getEmail(): string
    {
        $email = get_option('admin_email');

        return !empty($email) ? $email : 'hello@example-apartments.com';
    }
}
