#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""会话数测试/长连接测试Skill"""

import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(__file__))))

from skills.base_skill import BaseSkill
from network_tools import run_session_test


class SessionTestSkill(BaseSkill):
    """会话数测试/长连接测试Skill"""
    
    def get_metadata(self):
        return {
            "name": "session_test",
            "display_name": "会话数测试",
            "description": "测试最大并发连接数和长连接稳定性",
            "category": "advanced",
            "keywords": ["会话", "连接", "并发", "长连接", "session", "connection"],
            "parameters": [
                {
                    "name": "host",
                    "type": "string",
                    "required": True,
                    "description": "目标主机IP或域名"
                },
                {
                    "name": "port",
                    "type": "int",
                    "required": False,
                    "default": 80,
                    "description": "目标端口"
                },
                {
                    "name": "max_connections",
                    "type": "int",
                    "required": False,
                    "default": 1000,
                    "description": "最大连接数"
                }
            ],
            "examples": [
                "长连接测试baidu.com",
                "会话数测试192.168.1.1 80",
                "测试并发连接baidu.com"
            ],
            "requires_admin": False,
            "requires_ui": False
        }
    
    def execute(self, host: str, port: int = 80, max_connections: int = 1000) -> str:
        """执行会话数测试"""
        return run_session_test(host, port, max_connections)
