from dataclasses import dataclass, asdict

from domainmaster.commands.base import BaseCommand
from domainmaster.errors import DomainmasterError
from domainmaster.models.nsset import Nsset


class ShowNsset(BaseCommand):
    COMMAND = 'show nsset'

    @dataclass
    class Params:
        nsset: str


    def execute(self, params: Params) -> Nsset:
        payload = {
            'command': self.COMMAND,
            'params': asdict(params)
        }

        response = self.requestor.request(payload)

        if response['status'] != 'success':
            raise DomainmasterError(message=response['message'])

        response = Nsset(
            id=response['id'],
            contact_tech=response['contact_tech'],
            nserver=response['nserver'],
            glue=response['glue'],
            report_level=response['report_level']
        )
        return response
