<?php

namespace Devikit\Sellsy;

use Devikit\Sellsy\Admin\OrderColumns;
use Devikit\Sellsy\Admin\Settings;
use Devikit\Sellsy\Api\Client;
use Devikit\Sellsy\Frontend\Checkout;
use Devikit\Sellsy\Frontend\CheckoutBlocks;
use Devikit\Sellsy\Frontend\MyAccount;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class Plugin {

	/**
	 * @var Plugin|null
	 */
	private static $instance;

	/**
	 * @var Settings
	 */
	private $settings;

	/**
	 * @var Client
	 */
	private $api_client;

	/**
	 * @var InvoiceManager
	 */
	private $invoice_manager;

	/**
	 * @var TaxMapper
	 */
	private $tax_mapper;

	/**
	 * @var VatIdField
	 */
	private $vat_id_field;

	/**
	 * @var Checkout
	 */
	private $checkout;

	/**
	 * @var CheckoutBlocks
	 */
	private $checkout_blocks;

	/**
	 * @var OrderColumns
	 */
	private $order_columns;

	/**
	 * @var MyAccount
	 */
	private $my_account;

	/**
	 * @return Plugin
	 */
	public static function instance() {
		if ( is_null( self::$instance ) ) {
			self::$instance = new self();
		}
		return self::$instance;
	}

	private function __construct() {
		$this->init_hooks();
		$this->init_components();
	}

	private function init_hooks() {
		add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
	}

	private function init_components() {
		$this->settings        = new Settings();
		$this->api_client      = new Client( $this->settings );
		$this->tax_mapper      = new TaxMapper( $this->settings, $this->api_client );
		$this->invoice_manager = new InvoiceManager( $this->api_client, $this->settings, $this->tax_mapper );
		$this->vat_id_field    = new VatIdField();
		$this->checkout        = new Checkout();
		$this->checkout_blocks = new CheckoutBlocks();
		$this->my_account      = new MyAccount();
		$this->order_columns   = new OrderColumns();
	}

	public function enqueue_assets() {
		// Reserved for global admin assets.
	}

	/**
	 * @return Settings
	 */
	public function get_settings() {
		return $this->settings;
	}

	/**
	 * @return Client
	 */
	public function get_api_client() {
		return $this->api_client;
	}

	/**
	 * @return InvoiceManager
	 */
	public function get_invoice_manager() {
		return $this->invoice_manager;
	}

	/**
	 * @return TaxMapper
	 */
	public function get_tax_mapper() {
		return $this->tax_mapper;
	}
}
