from dataclasses import dataclass, asdict

from domainmaster.commands.base import BaseCommand
from domainmaster.errors import DomainmasterError
from domainmaster.models.domain import Domain


class ShowDomain(BaseCommand):
    COMMAND = 'show domain'

    @dataclass
    class Params:
        domain: str

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

        response = self.requestor.request(payload)

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

        response = Domain(
            domain=response['domain'],
            registrant=response['registrant'],
            tech=response['tech'],
            nserver=response['nserver'],
            glue=response['glue'],
            create_date=response['create_date'],
            expiry_date=response['expiry_date'],
            idacc=response['idacc'],
            iddealer=response['iddealer']
        )

        return response
