#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""DNS查询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_dns_query


class DnsQuerySkill(BaseSkill):
    """DNS查询Skill"""
    
    def get_metadata(self):
        return {
            "name": "dns_query",
            "display_name": "DNS查询",
            "description": "查询域名的DNS记录",
            "category": "network",
            "keywords": ["dns", "域名", "解析", "查询", "nslookup"],
            "parameters": [
                {
                    "name": "domain",
                    "type": "string",
                    "required": True,
                    "description": "要查询的域名"
                },
                {
                    "name": "record_type",
                    "type": "string",
                    "required": False,
                    "default": "A",
                    "description": "记录类型:A/AAAA/CNAME/MX/NS/TXT/PTR/SOA"
                }
            ],
            "examples": [
                "查询baidu.com的DNS",
                "dns查询example.com",
                "查询baidu.com的MX记录"
            ],
            "requires_admin": False,
            "requires_ui": False
        }
    
    def execute(self, domain: str, record_type: str = "A") -> str:
        """执行DNS查询"""
        # 确保record_type是大写
        record_type = record_type.upper()
        return run_dns_query(domain, record_type)
