<?php

declare(strict_types=1);

/*
 * PaypalServerSDKLib
 *
 * This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
 */

namespace PaypalServerSDKLib\Tests\UnitTests;

use PaypalServerSDKLib\Controllers\OrdersController;
use PaypalServerSDKLib\Models\Builders\ConfirmOrderRequestBuilder;
use PaypalServerSDKLib\Models\Builders\OrderRequestBuilder;
use PaypalServerSDKLib\Models\Builders\OrderTrackerRequestBuilder;
use PaypalServerSDKLib\Models\Builders\PatchBuilder;
use PaypalServerSDKLib\Models\Builders\PaymentSourceBuilder;
use PaypalServerSDKLib\Models\CheckoutPaymentIntent;
use PaypalServerSDKLib\Models\PatchOp;
use PaypalServerSDKLib\Tests\Controllers\BaseTestController;

class OrdersControllerTest extends BaseTestController
{
    /**
     * @var OrdersController OrdersController instance
     */
    protected static $controller;
    private const NON_EXISTENT_ORDER_ID = 'id-4';
    private const NON_EXISTENT_TRACKER_ID = '5UA89551P20376023-443844607820';
    private const ALREADY_CAPTURED_ID = '123';

    /**
     * Setup test class
     */
    public static function setUpBeforeClass(): void
    {
        self::$controller = parent::getClient()->getOrdersController();
    }

    public function testOrdersCreateWithStatus400()
    {
        // Parameters for the API call
        $request = [
            'body' => OrderRequestBuilder::init(
                CheckoutPaymentIntent::CAPTURE,
                []
            )->build(),
            'payPalRequestId' => 'PayPal-Request-Id',
            'payPalPartnerAttributionId' => 'PayPal-Partner-Attribution-Id2',
            'payPalClientMetadataId' => 'PayPal-Client-Metadata-Id',
            'prefer' => 'return=minimal'
        ];
        // Perform API call
        $result = self::$controller->ordersCreate($request);

        $headers = [];
        $headers['Content-Type'] = ['application/json', true];

        // Assert result with expected response
        $this->assertTrue($result->isError());
        $this->newTestCase($result->getResult())
            ->expectStatus(400)
            ->allowExtraHeaders()
            ->expectHeaders($headers)
            ->assert();
    }

    public function testOrdersPatchWithStatus400()
    {
        // Parameters for the API call
        $request = [
            'body' => PatchBuilder::init(
                PatchOp::ADD
            )->build(),
            'id' => self::NON_EXISTENT_ORDER_ID,
        ];
        // Perform API call
        $result = self::$controller->ordersPatch($request);

        $headers = [];
        $headers['Content-Type'] = ['application/json', true];

        // Assert result with expected response
        $this->assertTrue($result->isError());
        $this->newTestCase($result->getResult())
            ->expectStatus(400)
            ->allowExtraHeaders()
            ->expectHeaders($headers)
            ->assert();
    }

    public function testOrdersGetWithStatus204()
    {
        // Parameters for the API call
        $request = [
            'id' => self::NON_EXISTENT_ORDER_ID
        ];
        // Perform API call
        $result = self::$controller->ordersPatch($request);

        // Assert result with expected response
        $this->assertTrue($result->isSuccess());
        $this->newTestCase($result->getResult())
            ->expectStatus(204)
            ->assert();
    }

    public function testOrdersConfirmWithStatus404()
    {
        // Parameters for the API call
        $request = [
            'body' => ConfirmOrderRequestBuilder::init(
                PaymentSourceBuilder::init()->build()
            )->build(),
            'id' => self::NON_EXISTENT_ORDER_ID,
            'prefer' => 'return=minimal'
        ];
        // Perform API call
        $result = self::$controller->ordersConfirm($request);

        $headers = [];
        $headers['Content-Type'] = ['application/json', true];

        // Assert result with expected response
        $this->assertTrue($result->isError());
        $this->newTestCase($result->getResult())
            ->expectStatus(404)
            ->allowExtraHeaders()
            ->expectHeaders($headers)
            ->assert();
    }

    public function testOrdersAuthorizeWithStatus404()
    {
        // Parameters for the API call
        $request = [
            'id' => self::NON_EXISTENT_ORDER_ID,
            'prefer' => 'return=minimal'
        ];
        // Perform API call
        $result = self::$controller->ordersAuthorize($request);

        $headers = [];
        $headers['Content-Type'] = ['application/json', true];

        // Assert result with expected response
        $this->assertTrue($result->isError());
        $this->newTestCase($result->getResult())
            ->expectStatus(404)
            ->allowExtraHeaders()
            ->expectHeaders($headers)
            ->assert();
    }

    public function testOrdersTrackCreateWithStatus404()
    {
        // Parameters for the API call
        $request = [
            'id' => self::NON_EXISTENT_ORDER_ID,
            'body' => OrderTrackerRequestBuilder::init(
                self::ALREADY_CAPTURED_ID
            )->notifyPayer(false)->build(),
        ];
        // Perform API call
        $result = self::$controller->ordersTrackCreate($request);

        $headers = [];
        $headers['Content-Type'] = ['application/json', true];

        // Assert result with expected response
        $this->assertTrue($result->isError());
        $this->newTestCase($result->getResult())
            ->expectStatus(400)
            ->allowExtraHeaders()
            ->expectHeaders($headers)
            ->assert();
    }

    public function testOrdersTrackersPatchWithStatus404()
    {
        // Parameters for the API call
        $request = [
            'id' => self::NON_EXISTENT_ORDER_ID,
            'trackerId' => self::NON_EXISTENT_TRACKER_ID,
            'body' => [
                PatchBuilder::init(
                    PatchOp::REPLACE
                )
                    ->path('/notify_payer')
                    ->value(true)
                    ->build()
            ]
        ];
        // Perform API call
        $result = self::$controller->ordersTrackersPatch($request);

        $headers = [];
        $headers['Content-Type'] = ['application/json', true];

        // Assert result with expected response
        $this->assertTrue($result->isError());
        $this->newTestCase($result->getResult())
            ->expectStatus(404)
            ->allowExtraHeaders()
            ->expectHeaders($headers)
            ->assert();
    }
}
