from cifsdk.format.plugin import Plugin
import time

OUTPUT_FILE = '/etc/namedb'


class Bind(Plugin):

    def __init__(self, *args, **kwargs):
        super(Bind, self).__init__(*args, **kwargs)

        self.output = kwargs.get('output', OUTPUT_FILE)

    def __repr__(self):
        text = [
            '// generated by: {} at {}'.format('CIF', time.strftime('%Y-%M-%dT%H:%m:%S %Z'))
        ]
        for obs in self.data:
            if obs['otype'] is not 'fqdn':
                pass

            text.append('zone "{}" {{type master; file "{}";}};'.format(obs['observable'], self.output))

        return '\n'.join(text)