<?php

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

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

class CAAAdapter extends AbstractRCodeZeroAdapter
{
    /**
     * @param string $content
     */
    public function createRdata( $content )
    {
        $contentArray        = explode(' ', $content);
        $this->rdata         = new CAA();
        $this->rdata->flag   = $contentArray[0];
        $this->rdata->tag    = $contentArray[1];
        $this->rdata->target = trim($contentArray[2], '"');
    }

    /**
     * @param CAA $rdata
     * @return string
     */
    public function parseContentToApiFormat( $rdata )
    {
        $content = [
            $rdata->flag,
            $rdata->tag,
            ('"' . trim($rdata->target, '"') . '"')
        ];

        return implode(' ', $content);
    }
}