<?php

namespace Tests\Unit;

use App\Models\Package;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class PackagePaddleSyncErrorTest extends TestCase
{
    use RefreshDatabase;

    public function test_paddle_sync_error_message_returns_message_when_present(): void
    {
        $package = Package::factory()->create([
            'paddle_snapshot' => [
                'error' => [
                    'message' => 'Sync failed.',
                ],
            ],
        ]);

        $this->assertSame('Sync failed.', $package->paddle_sync_error_message);
    }

    public function test_paddle_sync_error_message_returns_null_when_missing(): void
    {
        $package = Package::factory()->create([
            'paddle_snapshot' => [
                'product' => [
                    'id' => 'pro_123',
                ],
            ],
        ]);

        $this->assertNull($package->paddle_sync_error_message);
    }
}
