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


class SubnetCalcSkill(BaseSkill):
    """子网计算Skill"""
    
    def get_metadata(self):
        return {
            "name": "subnet_calc",
            "display_name": "子网计算",
            "description": "计算IP地址的子网信息",
            "category": "network",
            "keywords": ["子网", "计算", "subnet", "掩码", "cidr"],
            "parameters": [
                {
                    "name": "ip_cidr",
                    "type": "string",
                    "required": True,
                    "description": "IP地址和子网掩码,格式:192.168.1.0/24"
                }
            ],
            "examples": [
                "计算192.168.1.0/24的子网",
                "子网计算10.0.0.0/8",
                "计算172.16.0.0/16"
            ],
            "requires_admin": False,
            "requires_ui": False
        }
    
    def execute(self, ip_cidr: str) -> str:
        """执行子网计算"""
        return run_subnet_calc(ip_cidr)
