<?php

namespace Kylin\Wechat\Tests\Unit;

use Kylin\Wechat\Tests\TestCase;
use Kylin\Wechat\Wechat\WechatManager;
use EasyWeChat\OfficialAccount\Application as OfficialAccountApplication;
use EasyWeChat\MiniProgram\Application as MiniProgramApplication;
use EasyWeChat\OpenPlatform\Application as OpenPlatformApplication;
use EasyWeChat\Work\Application as WorkApplication;
use EasyWeChat\OpenWork\Application as OpenWorkApplication;
use EasyWeChat\Payment\Application as PaymentApplication;

class WechatManagerTest extends TestCase
{
    /**
     * Test that we can get an instance of WechatManager.
     */
    public function testCanGetWechatManagerInstance()
    {
        $wechatManager = $this->app->make(WechatManager::class);
        $this->assertInstanceOf(WechatManager::class, $wechatManager);
    }

    /**
     * Test that we can get an official account instance.
     */
    public function testCanGetOfficialAccountInstance()
    {
        $wechatManager = $this->app->make(WechatManager::class);
        $officialAccount = $wechatManager->officialAccount();
        $this->assertInstanceOf(OfficialAccountApplication::class, $officialAccount);
    }

    /**
     * Test that we can get a mini program instance.
     */
    public function testCanGetMiniProgramInstance()
    {
        $wechatManager = $this->app->make(WechatManager::class);
        $miniProgram = $wechatManager->miniProgram();
        $this->assertInstanceOf(MiniProgramApplication::class, $miniProgram);
    }

    /**
     * Test that we can get an open platform instance.
     */
    public function testCanGetOpenPlatformInstance()
    {
        $wechatManager = $this->app->make(WechatManager::class);
        $openPlatform = $wechatManager->openPlatform();
        $this->assertInstanceOf(OpenPlatformApplication::class, $openPlatform);
    }

    /**
     * Test that we can get a work instance.
     */
    public function testCanGetWorkInstance()
    {
        $wechatManager = $this->app->make(WechatManager::class);
        $work = $wechatManager->work();
        $this->assertInstanceOf(WorkApplication::class, $work);
    }

    /**
     * Test that we can get an open work instance.
     */
    public function testCanGetOpenWorkInstance()
    {
        $wechatManager = $this->app->make(WechatManager::class);
        $openWork = $wechatManager->openWork();
        $this->assertInstanceOf(OpenWorkApplication::class, $openWork);
    }

    /**
     * Test that we can get a payment instance.
     */
    public function testCanGetPaymentInstance()
    {
        $wechatManager = $this->app->make(WechatManager::class);
        $payment = $wechatManager->payment();
        $this->assertInstanceOf(PaymentApplication::class, $payment);
    }

    /**
     * Test that the driver method works correctly.
     */
    public function testDriverMethodWorksCorrectly()
    {
        $wechatManager = $this->app->make(WechatManager::class);
        $result = $wechatManager->driver('official_account');
        $this->assertInstanceOf(WechatManager::class, $result);
    }
}