<?php

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

use MGModule\DNSManager2\mgLibs\custom\dns\record\type\DS;

class DSAdapter extends AbstractPowerDNSv4Adapter
{
    /**
     * @param string $content
     */
    public function createRdata( $content )
    {
        $contentArray            = explode(' ', $content);
        $this->rdata             = new DS();
        $this->rdata->keytag     = $contentArray[0];
        $this->rdata->algorithm  = $contentArray[1];
        $this->rdata->digesttype = $contentArray[2];
        $this->rdata->digest     = strtoupper($contentArray[3]);
    }

    /**
     * @param DS $rdata
     * @return string
     */
    public function parseContentToApiFormat( $rdata )
    {
        $content = [
            $rdata->keytag,
            $rdata->algorithm,
            $rdata->digesttype,
            strtolower($rdata->digest)
        ];
        return implode(' ', $content);
    }
}