<?php
namespace App\Apollo\StructureParser\Structures\Ticketing;

class Remarks extends \App\Apollo\StructureParser\Structures\Base\Remarks {
    protected function _getData() {
        list($parsedStructure, $transactionType, $transactionIndexes) = $this->getTransactionDetails();

        $item = new \App\Apollo\StructureParser\Types\Remarks();

        if ($parsedStructure['A14']) {
            foreach ($parsedStructure['A14'] as $A14) {
                $comp = new \App\Apollo\StructureParser\Types\RemarkComponent();
                $comp->type = 'public';
                $comp->content = $A14['A14']['A14DTA'];
                $item->append($comp);
            }
        }

        if ($parsedStructure['A15']) {
            $A02 = $parsedStructure['A02'][$transactionIndexes['k02']];

            // load remarks associated with all segments
            foreach ($parsedStructure['A15'] as $A15) {
                if (0 == $A15['A15']['A15SEG']) {
                    $comp = new \App\Apollo\StructureParser\Types\RemarkComponent();
                    $comp->type = 'public';
                    $comp->content = $A15['A15']['A15DTA'];
                    $item->append($comp);
                }
            }

            // load remarks associated with specific segments
            foreach ($parsedStructure['A04'] as $k04 => $a04) {
                if ($A15['A15']['A15SEG'] == $a04['A04']['A04ITN']) {
                    $comp = new \App\Apollo\StructureParser\Types\RemarkComponent();
                    $comp->type = 'associated';
                    $comp->content = $A15['A15']['A15DTA'];
                    $item->append($comp);
                }
            }
        }

        return $item;
    }
}
