from dataclasses import dataclass, asdict
from typing import List

from domainmaster.commands.base import BaseCommand
from domainmaster.errors import DomainmasterError


class RegisterNsset(BaseCommand):
    COMMAND = 'register %s nsset'

    @dataclass
    class Params:
        id: str
        contact_tech: List[str]
        nserver: List[str]
        glue: List[str]
        report_level: int


    def execute(self, nsset: str, params):
        payload = {
            'command': self.COMMAND % nsset,
            'params': asdict(params)
        }

        response = self.requestor.request(payload)

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

        return response
