<?php

namespace Devikit\Fakturowo;

use Devikit\Fakturowo\Admin\Settings;
use Devikit\Fakturowo\Admin\OrderColumns;
use Devikit\Fakturowo\Api\Client;
use Devikit\Fakturowo\Frontend\Checkout;
use Devikit\Fakturowo\Frontend\CheckoutBlocks;
use Devikit\Fakturowo\NipField;

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

class Plugin {

    /**
     * Singleton instance
     *
     * @var Plugin
     */
    private static $instance;

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

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

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

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

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

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

    /**
     * @var NipField
     */
    private $nip_field;

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

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

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

    /**
     * Initialize components
     */
    private function init_components() {
        $this->settings = new Settings();
        
        $api_key = $this->settings->get_option( 'api_key' );
        $api_url = $this->settings->get_option( 'api_url' );
        $this->api_client = new Client( $api_key, $api_url );

        $this->invoice_manager = new InvoiceManager( $this->api_client, $this->settings );
        $this->checkout = new Checkout();
        $this->checkout_blocks = new CheckoutBlocks();
        $this->order_columns = new OrderColumns();
        $this->nip_field = new NipField();
    }

    /**
     * Enqueue assets
     */
    public function enqueue_assets() {
        // Enqueue styles/scripts if needed
    }

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

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

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





