<?php

namespace Tests\Feature;

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

class AdminMerchantIndexGovernanceLinksShouldIncludePaidNoReceiptTest extends TestCase
{
    use RefreshDatabase;

    protected function loginAsPlatformAdmin(): void
    {
        $this->seed();

        $this->post('/admin/login', [
            'email' => 'platform.admin@demo.local',
            'password' => 'Platform@123456',
        ])->assertRedirect('/admin');
    }

    public function test_merchant_index_governance_links_should_include_paid_no_receipt(): void
    {
        $this->loginAsPlatformAdmin();

        $merchant = Merchant::query()->create([
            'name' => '站点治理已付无回执测试站点',
            'slug' => 'merchant-paid-no-receipt-link',
            'plan' => 'pro',
            'status' => 'active',
            'contact_name' => '张三',
            'contact_phone' => '13800138000',
            'contact_email' => 'merchant-paid-no-receipt@example.com',
        ]);

        $res = $this->get('/admin/merchants');
        $res->assertOk();

        $html = (string) $res->getContent();
        $this->assertStringContainsString('已付无回执', $html);

        $expectedBack = urlencode('/admin/merchants');
        $this->assertStringContainsString('/admin/platform-orders?merchant_id=' . $merchant->id . '&payment_status=paid&receipt_status=none&back=' . $expectedBack, $html);
    }
}
