from cifsdk.format.plugin import Plugin
import time
from pprint import pprint

OUTPUT_FILE = '/etc/bind/rpz'


class BindRPZ(Plugin):

    def __init__(self, *args, **kwargs):
        super(BindRPZ, 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')),
            ';RPZ DATA!',
            '$TTL    1',
            '@       IN      SOA     localhost. root.localhost. (',
            '                     {}         ; Serial'.format(int(time.time())),
            '                         604800         ; Refresh',
            '                          86400         ; Retry',
            '                        2419200         ; Expire',
            '                          86400 )       ; Negative Cache TTL',
            ';',
            '@       IN      NS      localhost.'
        ]
        for obs in self.data:
            if obs['otype'] is not 'fqdn':
                pass

            text.append('{}        CNAME .'.format(obs['observable'], self.output))
            text.append('*.{}        CNAME .'.format(obs['observable'], self.output))

        return '\n'.join(text)
