<?php

declare(strict_types=1);

namespace Tests\Integration\Services;

use Tests\TestCase;

class OrderCreateServiceTest extends TestCase
{
    protected function setUp(): void
    {
        parent::setUp();
    }

    /** @test */
    public function rejects_order_without_firstname(): void
    {
        $this->markTestSkipped('Requires OpenCart Registry and Cart');
    }

    /** @test */
    public function rejects_order_without_phone(): void
    {
        $this->markTestSkipped('Requires OpenCart Registry and Cart');
    }

    /** @test */
    public function rejects_order_with_invalid_email(): void
    {
        $this->markTestSkipped('Requires OpenCart Registry and Cart');
    }

    /** @test */
    public function allows_empty_email_field(): void
    {
        $this->markTestSkipped('Requires OpenCart cart session');
    }

    /** @test */
    public function creates_order_with_valid_data(): void
    {
        $this->markTestSkipped('Requires OpenCart cart session with products');
        
        $validData = [
            'firstName' => 'John',
            'lastName' => 'Doe',
            'phone' => '+79991234567',
            'email' => 'john@example.com',
            'address' => 'Test Address',
            'comment' => 'Test comment',
            'tgData' => ['user' => ['id' => 123]],
        ];

        $service = $this->factory(OrderCreateService::class);
        $result = $service->create($validData, [
            'ip' => '127.0.0.1',
            'user_agent' => 'test-agent',
        ]);

        $this->assertIsArray($result);
        $this->assertArrayHasKey('id', $result);
        $this->assertArrayHasKey('created_at', $result);
        $this->assertArrayHasKey('total', $result);
    }

    /** @test */
    public function preserves_telegram_user_data(): void
    {
        $this->markTestSkipped('Requires OpenCart cart session with products');
        
        $tgData = [
            'user' => [
                'id' => 123456,
                'first_name' => 'Test',
                'allows_write_to_pm' => true,
            ],
        ];

        $orderData = [
            'firstName' => 'John',
            'lastName' => 'Doe',
            'phone' => '+79991234567',
            'email' => 'test@example.com',
            'address' => 'Test',
            'comment' => '',
            'tgData' => $tgData,
        ];

        $service = $this->factory(OrderCreateService::class);
        $result = $service->create($orderData, ['ip' => '127.0.0.1']);

        // Проверяем, что заказ создан
        $this->assertIsArray($result);
        $this->assertArrayHasKey('id', $result);
    }

}

