<?php

/**
 * 文件功能：后台 VIP 管理功能测试
 * 校验管理员可以查看某个会员等级下的会员名单与会员状态。
 */

namespace Tests\Feature\Feature;

use App\Models\User;
use App\Models\VipLevel;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

/**
 * 后台 VIP 管理功能测试
 * 负责验证会员等级成员列表页的展示结果。
 */
class AdminVipControllerTest extends TestCase
{
    use RefreshDatabase;

    /**
     * 测试超级管理员可以查看某个会员等级下的会员名单。
     */
    public function test_admin_can_view_vip_level_members_page(): void
    {
        $admin = User::factory()->create([
            'user_level' => 100,
        ]);

        $vipLevel = VipLevel::create([
            'name' => '黄金会员',
            'icon' => '👑',
            'color' => '#f59e0b',
            'exp_multiplier' => 1.5,
            'jjb_multiplier' => 1.2,
            'sort_order' => 1,
            'price' => 100,
            'duration_days' => 30,
            'join_effect' => 'none',
            'leave_effect' => 'none',
            'join_banner_style' => 'aurora',
            'leave_banner_style' => 'farewell',
            'allow_custom_messages' => true,
        ]);

        User::factory()->create([
            'username' => 'active_member',
            'vip_level_id' => $vipLevel->id,
            'hy_time' => now()->addDays(10),
        ]);

        User::factory()->create([
            'username' => 'permanent_member',
            'vip_level_id' => $vipLevel->id,
            'hy_time' => null,
        ]);

        User::factory()->create([
            'username' => 'expired_member',
            'vip_level_id' => $vipLevel->id,
            'hy_time' => now()->subDay(),
        ]);

        User::factory()->create([
            'username' => 'other_level_member',
        ]);

        $response = $this->actingAs($admin)->get(route('admin.vip.members', $vipLevel->id));

        $response->assertOk();
        $response->assertSee('黄金会员 会员列表');
        $response->assertSee('active_member');
        $response->assertSee('permanent_member');
        $response->assertSee('expired_member');
        $response->assertDontSee('other_level_member');
        $response->assertSee('当前有效');
        $response->assertSee('永久会员');
        $response->assertSee('已过期');
    }
}
