<?php

namespace MGModule\DNSManager2\mgLibs\custom\dns\submodules\PowerDNSv4\Adapters;

use MGModule\DNSManager2\mgLibs\custom\dns\record\type\AFSDB;
use MGModule\DNSManager2\mgLibs\custom\helpers\IdnaHelper;

class AFSDBAdapter extends AbstractPowerDNSv4Adapter
{
    /**
     * @param string $content
     */
    public function createRdata( $content )
    {
        $contentArray = explode(' ', $content);
        $this->rdata = new AFSDB();
        $this->rdata->subtype = $contentArray[0];
        $this->rdata->hostname = $this->contentToRelative(IdnaHelper::idnaDecode($contentArray[1]));
    }

    /**
     * @param AFSDB $rdata
     * @return string
     */
    public function parseContentToApiFormat( $rdata )
    {
        $content = [
            $rdata->subtype,
            $this->contentToAbsolute(IdnaHelper::idnaEncode($rdata->hostname))
        ];
        return  implode(' ', $content);
    }
}