<?php

namespace SheetWise;

use SheetWise\Api\Backfill;
use SheetWise\Api\Integrations;
use SheetWise\Api\Settings;
use SheetWise\Api\Sheet;
use SheetWise\Api\SheetHeaders;
use SheetWise\Api\SheetPermissions;
use SheetWise\Api\SyncLogs;
use SheetWise\Api\TestSync;
use SheetWise\Traits\ContainerTrait;

class Api {
	use ContainerTrait;

	/**
	 * Api constructor.
	 */
	public function __construct() {
		$this->container['settings']     = new Settings();
		$this->container['sheet']        = new Sheet();
		$this->container['integrations'] = new Integrations();
		$this->container['sync_logs']    = new SyncLogs();
		$this->container['test_sync']        = new TestSync();
		$this->container['sheet_headers']    = new SheetHeaders();
		$this->container['sheet_permissions'] = new SheetPermissions();
		$this->container['backfill']          = new Backfill();

		add_action( 'rest_api_init', [ $this, 'init_api' ] );
	}

	/**
	 * Initialize API
	 *
	 * @since 1.0.0
	 *
	 * @return void
	 */
	public function init_api() {
		foreach ( $this->container as $class ) {
			$object = new $class();
			$object->register_routes();
		}
	}
}
