from dataclasses import dataclass, asdict
from typing import List

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


class ChangeKeyset(BaseCommand):
    COMMAND = 'Change %s keyset'

    @dataclass
    class Params:
        id: str
        contact_tech: List[str]
        dns_key: List[str]
        # TODO tu sa este ma urobit nieco s contactom a passwordom ale este neviem ze co

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

        response = self.requestor.request(payload)

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

        return response
