<?php

namespace Tests\Feature\Api;

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

class GiftVoucherLookupTest extends TestCase
{
    use RefreshDatabase;

    public function test_it_returns_voucher_by_checkout_id(): void
    {
        $voucher = GiftVoucher::factory()->create([
            'code' => 'GIFT-TESTCODE',
            'amount' => 59.00,
            'currency' => 'EUR',
            'paddle_checkout_id' => 'chk_look_123',
            'status' => GiftVoucher::STATUS_ISSUED,
        ]);

        $response = $this->getJson('/api/v1/marketing/gift-vouchers/lookup?checkout_id=chk_look_123');

        $response->assertOk()
            ->assertJsonPath('data.code', $voucher->code)
            ->assertJsonPath('data.amount', 59)
            ->assertJsonPath('data.currency', 'EUR');
    }

    public function test_it_returns_voucher_by_code(): void
    {
        $voucher = GiftVoucher::factory()->create([
            'code' => 'GIFT-CODE',
            'amount' => 29.00,
            'currency' => 'EUR',
        ]);

        $response = $this->getJson('/api/v1/marketing/gift-vouchers/lookup?code=gift-code');

        $response->assertOk()
            ->assertJsonPath('data.code', $voucher->code)
            ->assertJsonPath('data.amount', 29);
    }

    public function test_it_requires_identifier(): void
    {
        $response = $this->getJson('/api/v1/marketing/gift-vouchers/lookup');

        $response->assertStatus(422);
    }
}
