<?php

/**
 * Abstract online solution settings model.
 *
 * @package northmill-online-shared
 */
declare (strict_types=1);
namespace Northmill_Online_Shared_Sync\Northmill_Online_Shared\Modules\Admin\Pages\Page\Admin_Sync_Settings\Models;

use Northmill_Online_Shared_Sync\Northmill_Online_Shared\Abstracts\Data_Model;
use Northmill_Online_Shared_Sync\Northmill_Online_Shared\Modules\Admin\Pages\Page\Admin_Sync_Settings\Models\Properties\Settings_Featured_Group_Model;
use Northmill_Online_Shared_Sync\Northmill_Online_Shared\Modules\Admin\Pages\Page\Admin_Sync_Settings\Models\Properties\Settings_Image_Model;
use Northmill_Online_Shared_Sync\Northmill_Online_Shared\Modules\Admin\Pages\Page\Admin_Sync_Settings\Models\Properties\Settings_Payment_Method_Model;
defined('ABSPATH') || exit;
/**
 * Class Abstract_Online_Solution_Settings_Model
 */
abstract class Abstract_Online_Solution_Settings_Model extends Data_Model
{
    /**
     * Company name.
     *
     * @var string|null
     */
    public ?string $CompanyName;
    /**
     * Address 1.
     *
     * @var string|null
     */
    public ?string $Address1;
    /**
     * Address 2.
     *
     * @var string|null
     */
    public ?string $Address2;
    /**
     * Post code.
     *
     * @var string|null
     */
    public ?string $PostCode;
    /**
     * City.
     *
     * @var string|null
     */
    public ?string $City;
    /**
     * Country.
     * This is unused since we currently only support Sweden.
     *
     * @var string|null
     */
    public ?string $Country;
    /**
     * Telephone.
     * We currently don't use this.
     * In the future it could, for instance, be used for displaying a phone number in frontend.
     *
     * @var string|null
     */
    public ?string $Telephone;
    /**
     * Email.
     *
     * @var string|null
     */
    public ?string $Email;
    /**
     * Site logotypes.
     *
     * @var Settings_Image_Model[]
     */
    public array $SiteLogotypes;
    /**
     * Site favicons.
     *
     * @var Settings_Image_Model[]
     */
    public array $SiteFavicons;
    /**
     * Content for the home page.
     *
     * @var string
     */
    public string $ContentHomePage;
    /**
     * Content for the footer text.
     *
     * @var string
     */
    public string $ContentFooterText;
    /**
     * Featured article groups.
     * Note that the actual group needs to be synced by Northmill Sync.
     *
     * @var Settings_Featured_Group_Model[]
     */
    public array $FeaturedGroups = array();
    /**
     * Payment methods.
     *
     * @var Settings_Payment_Method_Model[]
     */
    public array $PaymentMethods;
    /**
     * Check if the site is enabled from the current settings.
     *
     * @return bool
     */
    public function is_enabled(): bool
    {
        $payment_gateways = WC()->payment_gateways()->get_available_payment_gateways();
        return !empty($payment_gateways);
    }
    /**
     * Get the section active for the preview.
     *
     * @return array
     *
     * @used Northmill Express Order
     * @used Northmill Webshop Theme
     */
    public function get_preview_active_section(): array
    {
        return array('label' => __('Active', 'northmill-online-shared'), 'values' => array(array('name' => 'Active', 'label' => __('Activated', 'northmill-online-shared'), 'value' => $this->is_enabled() ? __('Yes', 'northmill-online-shared') : __('No', 'northmill-online-shared'), 'mark' => $this->is_enabled() ? 'yes' : 'no')));
    }
    /**
     * Get the section general for the preview.
     *
     * @return array
     *
     * @used Northmill Express Order
     * @used Northmill Webshop Theme
     */
    public function get_preview_general_section(): array
    {
        return array('label' => __('General', 'northmill-online-shared'), 'values' => array(array('name' => 'CompanyName', 'label' => __('Company name', 'northmill-online-shared'), 'value' => $this->CompanyName), array('name' => 'Address1', 'label' => __('Address 1', 'northmill-online-shared'), 'value' => $this->Address1), array('name' => 'Address2', 'label' => __('Address 2', 'northmill-online-shared'), 'value' => $this->Address2), array('name' => 'PostCode', 'label' => __('Post code', 'northmill-online-shared'), 'value' => $this->PostCode), array('name' => 'City', 'label' => __('City', 'northmill-online-shared'), 'value' => $this->City), array('name' => 'Country', 'label' => __('Country', 'northmill-online-shared'), 'value' => $this->Country), array('name' => 'Telephone', 'label' => __('Telephone', 'northmill-online-shared'), 'value' => $this->Telephone), array('name' => 'Email', 'label' => __('Email', 'northmill-online-shared'), 'value' => $this->Email)));
    }
    /**
     * Get the section site for the preview.
     *
     * @param array $additional_fields_before Fields to add before the main fields.
     * @param array $additional_fields_after Fields to add after the main fields.
     *
     * @return array
     *
     * @used Northmill Express Order
     * @used Northmill Webshop Theme
     */
    public function get_preview_site_section(array $additional_fields_before = array(), array $additional_fields_after = array()): array
    {
        return array('label' => __('Site', 'northmill-online-shared'), 'values' => array_merge($additional_fields_before, array(array('name' => 'SiteLogotypes', 'label' => __('Logotypes', 'northmill-online-shared'), 'value' => $this->SiteLogotypes), array('name' => 'SiteFavicons', 'label' => __('Favicons', 'northmill-online-shared'), 'value' => $this->SiteFavicons)), $additional_fields_after));
    }
    /**
     * Get the section payment methods for the preview.
     *
     * @return array
     *
     * @used Northmill Express Order
     * @used Northmill Webshop Theme
     */
    public function get_preview_payment_methods_section(): array
    {
        $previews = array();
        if (!empty($this->PaymentMethods)) {
            foreach ($this->PaymentMethods as $payment_method) {
                $settings_values = array('Title' => $payment_method->get_settings_title(), 'Description' => $payment_method->get_settings_description(), 'Username' => $payment_method->get_settings_username(), 'Password' => $payment_method->get_settings_password(), 'Key' => $payment_method->get_settings_key());
                $previews[] = array('label' => __('Payment method', 'northmill-online-shared') . ': ' . $payment_method->get_name(), 'values' => array(array('name' => $payment_method->get_type() . 'IsEnabled', 'label' => __('Is Enabled', 'northmill-online-shared'), 'value' => $payment_method->is_enabled() ? __('Enabled', 'northmill-online-shared') : __('Disabled', 'northmill-online-shared'), 'mark' => $payment_method->is_enabled() ? 'yes' : 'no'), array('name' => $payment_method->get_type() . 'Type', 'label' => __('Type', 'northmill-online-shared'), 'value' => $payment_method->get_type()), array('name' => $payment_method->get_type() . 'Settings', 'label' => __('Settings', 'northmill-online-shared'), 'value' => implode("\n", $settings_values))));
            }
        }
        return $previews;
    }
    /**
     * Get the array of Featured groups for the preview.
     *
     * @return array
     *
     * @used Northmill Express Order
     * @used Northmill Webshop Theme
     */
    public function get_preview_featured_groups(): array
    {
        return array(
            'name' => 'FeaturedGroups',
            'label' => __('Featured groups', 'northmill-online-shared'),
            'value' => $this->FeaturedGroups,
            // translators: [moreflo-content-featured-groups] is a shortcode.
            'usage' => sprintf(__('Usage: %s', 'northmill-online-shared'), '<i>[moreflo-content-featured-groups]</i>'),
        );
    }
}
