<?php

namespace MGModule\DNSManager2\mgLibs\custom\dns\submodules\AWSRoute53;

class AWSRoute53XmlRequestHelper
{
    const RECORD_REQUEST = 'recordBody';   
    const RECORD_ALIAS_REQUEST = 'recordAliasBody';
    const RECORD_NS_REQUEST = 'recordNSBody';
    const RECORD_NS_HOST = 'recordNSHostBody';
    const ZONE_REQUEST = 'zoneBody';
    const ZONE_REQUEST_DELEGATION_SET = 'zoneBodyDelegationSet';    
    
    public static function prepareResponseBody($type, $params)
    {
        $responseBody = self::loadResponseFromXmlFile($type);
        if(!$responseBody)
        {
            return false;
        }
        
        self::parseResponseBody($responseBody, $params);
        
        return $responseBody;
    }
    
    public static function loadResponseFromXmlFile($type)
    {
        $includePath = __DIR__.DIRECTORY_SEPARATOR.'xmlForms'.DIRECTORY_SEPARATOR.$type.'.xml';
        if(!file_exists($includePath))
        {
            return false;
        }
        
        $requestBody = file_get_contents($includePath);
        
        return $requestBody;
    }
    
    public static function parseResponseBody(&$responseBody, $params)
    {
        foreach($params as $key => $value)
        {
            $responseBody = str_replace(':'.$key.':', $value, $responseBody);
        }
    }
}
