<?php

/**
 * Creates Hub account models.
 *
 * @package northmill-online-shared
 */
declare (strict_types=1);
namespace Northmill_Online_Shared_Checkout\Northmill_Online_Shared\Abstracts\Hub_API\Hub_Accounts;

use Northmill_Online_Shared_Checkout\Northmill_Online_Shared\Abstracts\Hub_API\Hub_Accounts\Models\Hub_Account_Model;
use WP_Post;
defined('ABSPATH') || exit;
/**
 * Class Factory
 */
class Factory
{
    /**
     * Create a Hub account model.
     *
     * @param array $data Array of data to create the model from.
     *
     * @return Hub_Account_Model
     */
    public static function create(array $data): Hub_Account_Model
    {
        return new Hub_Account_Model(array('wp_id' => $data['wp_id'] ?? 0, 'display_name' => $data['display_name'] ?? $data['org_num'] ?? '', 'url' => $data['url'] ?? '', 'user' => $data['user'] ?? '', 'pass' => $data['pass'] ?? '', 'env' => $data['env'] ?? '', 'type' => $data['type'] ?? 'stock', 'enabled' => (bool) ($data['enabled'] ?? \true), 'allowed_shipping_methods' => $data['allowed_shipping_methods'] ?? array(), 'org_name' => $data['org_name'] ?? '', 'org_num' => $data['org_num'] ?? '', 'last_sync' => $data['last_sync'] ?? '', 'article_account_codes' => $data['article_account_codes'] ?? array(), 'income_account_codes' => $data['income_account_codes'] ?? array(), 'vat_account_codes' => $data['vat_account_codes'] ?? array(), 'shipping_settings' => $data['shipping_settings'] ?? array(), 'partial_refund_article_sku' => $data['partial_refund_article_sku'] ?? ''));
    }
    /**
     * Create a Hub model from CPT.
     *
     * @param WP_Post $post The post to create the model from.
     *
     * @return Hub_Account_Model
     */
    public static function create_from_wp_post(WP_Post $post): Hub_Account_Model
    {
        return new Hub_Account_Model(array('wp_id' => $post->ID, 'display_name' => WP_Repository_Metas::get_single($post->ID, 'display_name'), 'enabled' => (bool) WP_Repository_Metas::get_single($post->ID, 'enabled'), 'allowed_shipping_methods' => WP_Repository_Metas::get_single($post->ID, 'allowed_shipping_methods'), 'url' => WP_Repository_Metas::get_single($post->ID, 'url'), 'user' => WP_Repository_Metas::get_single($post->ID, 'user'), 'pass' => WP_Repository_Metas::get_single($post->ID, 'pass'), 'env' => WP_Repository_Metas::get_single($post->ID, 'env'), 'type' => WP_Repository_Metas::get_single($post->ID, 'type'), 'org_name' => WP_Repository_Metas::get_single($post->ID, 'org_name'), 'org_num' => WP_Repository_Metas::get_single($post->ID, 'org_num'), 'last_sync' => WP_Repository_Metas::get_single($post->ID, 'last_sync'), 'article_account_codes' => WP_Repository_Metas::get_single($post->ID, 'article_account_codes'), 'income_account_codes' => WP_Repository_Metas::get_single($post->ID, 'income_account_codes'), 'vat_account_codes' => WP_Repository_Metas::get_single($post->ID, 'vat_account_codes'), 'shipping_settings' => WP_Repository_Metas::get_single($post->ID, 'shipping_settings'), 'partial_refund_article_sku' => WP_Repository_Metas::get_single($post->ID, 'partial_refund_article_sku')));
    }
}
