<?php
declare(strict_types=1);

namespace Tests\Unit\Contracts;

use Tests\TestCase;
use App\Core\Contracts\RuleEngineInterface;
use App\Core\Contracts\PaymentProcessorInterface;
use App\Core\Contracts\StockManagerInterface;
use App\Core\Contracts\WorkflowEngineInterface;
use App\Core\Contracts\JournalServiceInterface;
use App\Core\Contracts\EventDispatcherInterface;
use App\Modules\Rules\RuleEngineAdapter;
use App\Modules\Payments\PaymentProcessorAdapter;
use App\Modules\Inventory\StockManagerAdapter;
use App\Modules\Workflow\WorkflowEngineAdapter;
use App\Modules\Accounting\JournalServiceAdapter;

final class ContractComplianceTest extends TestCase
{
    public function testRuleEngineAdapterImplementsInterface(): void
    {
        $adapter = new RuleEngineAdapter();
        $this->assertInstanceOf(RuleEngineInterface::class, $adapter);
    }

    public function testPaymentProcessorAdapterImplementsInterface(): void
    {
        $adapter = new PaymentProcessorAdapter();
        $this->assertInstanceOf(PaymentProcessorInterface::class, $adapter);
    }

    public function testStockManagerAdapterImplementsInterface(): void
    {
        $adapter = new StockManagerAdapter();
        $this->assertInstanceOf(StockManagerInterface::class, $adapter);
    }

    public function testWorkflowEngineAdapterImplementsInterface(): void
    {
        $adapter = new WorkflowEngineAdapter();
        $this->assertInstanceOf(WorkflowEngineInterface::class, $adapter);
    }

    public function testJournalServiceAdapterImplementsInterface(): void
    {
        $adapter = new JournalServiceAdapter();
        $this->assertInstanceOf(JournalServiceInterface::class, $adapter);
    }

    public function testInterfacesDefineExpectedMethods(): void
    {
        $ruleEngine = new \ReflectionClass(RuleEngineInterface::class);
        $this->assertTrue($ruleEngine->hasMethod('get'));
        $this->assertTrue($ruleEngine->hasMethod('getValue'));
        $this->assertTrue($ruleEngine->hasMethod('getAll'));
        $this->assertTrue($ruleEngine->hasMethod('getEffective'));
        $this->assertTrue($ruleEngine->hasMethod('require'));
        $this->assertTrue($ruleEngine->hasMethod('requireValue'));

        $payment = new \ReflectionClass(PaymentProcessorInterface::class);
        $this->assertTrue($payment->hasMethod('processPayment'));
        $this->assertTrue($payment->hasMethod('voidPayment'));
        $this->assertTrue($payment->hasMethod('hasPaid'));
        $this->assertTrue($payment->hasMethod('totalPaid'));

        $stock = new \ReflectionClass(StockManagerInterface::class);
        $this->assertTrue($stock->hasMethod('moveStock'));
        $this->assertTrue($stock->hasMethod('getAvailableQuantity'));
        $this->assertTrue($stock->hasMethod('getTotalStock'));

        $workflow = new \ReflectionClass(WorkflowEngineInterface::class);
        $this->assertTrue($workflow->hasMethod('createInstance'));
        $this->assertTrue($workflow->hasMethod('transition'));
        $this->assertTrue($workflow->hasMethod('getCurrentState'));

        $journal = new \ReflectionClass(JournalServiceInterface::class);
        $this->assertTrue($journal->hasMethod('createEntry'));
        $this->assertTrue($journal->hasMethod('postEntry'));
        $this->assertTrue($journal->hasMethod('reverseEntry'));
    }
}
