#!/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_windows_command


class FirewallSkill(BaseSkill):
    """防火墙管理Skill"""
    
    def get_metadata(self):
        return {
            "name": "firewall",
            "display_name": "防火墙管理",
            "description": "管理Windows防火墙(开启/关闭/查看状态)",
            "category": "system",
            "keywords": ["防火墙", "firewall", "开启", "关闭", "状态"],
            "parameters": [
                {
                    "name": "action",
                    "type": "string",
                    "required": True,
                    "description": "操作类型:on(开启)/off(关闭)/status(查看状态)"
                }
            ],
            "examples": [
                "关闭防火墙",
                "开启防火墙",
                "查看防火墙状态"
            ],
            "requires_admin": True,
            "requires_ui": False
        }
    
    def execute(self, action: str) -> str:
        """执行防火墙操作"""
        action = action.lower()
        
        if action in ["off", "关闭", "禁用"]:
            command = "netsh advfirewall set allprofiles state off"
            result = run_windows_command(command)
            return f"🔓 正在关闭防火墙...\n\n{result}\n\n⚠️ 警告:关闭防火墙会降低系统安全性!"
        
        elif action in ["on", "开启", "启用"]:
            command = "netsh advfirewall set allprofiles state on"
            result = run_windows_command(command)
            return f"🔒 正在开启防火墙...\n\n{result}"
        
        elif action in ["status", "状态", "查看"]:
            command = "netsh advfirewall show allprofiles state"
            result = run_windows_command(command)
            return f"🛡️ 防火墙状态:\n\n{result}"
        
        else:
            return f"❌ 未知操作: {action}\n\n支持的操作:\n  • on/开启 - 开启防火墙\n  • off/关闭 - 关闭防火墙\n  • status/状态 - 查看状态"
