<?php

namespace App\Services\PwApi\Territory;

class TerritoryService extends \App\Services\PwApi\Core\PwApiService
{
    public function getTerritories()
    {
        $pack = pack('N*', -1, 1);
        $data = $this->gamed->SendToGamedBD($this->gamed->createHeader($this->data['code']['getTerritory'], $pack));
        $length = 0;
        $this->gamed->unpackCuint($data, $length);
        $this->gamed->unpackCuint($data, $length);
        $length += 6;
        $data = substr($data, $length);

        return $this->gamed->unmarshal($data, $this->data['GTerritoryDetail']);
    }

    public function getRaw($table, $handler = '', $key = '')
    {
        $pack = pack('N*', -1).$this->gamed->packLongOctet($table).$this->gamed->packOctet($handler).$this->gamed->packOctet($key);
        $data = $this->gamed->deleteHeader($this->gamed->SendToGamedBD($this->gamed->createHeader(3055, $pack)));

        return $this->gamed->unmarshal($data, $this->data['RawRead']);
    }

    public function parseOctet($octet, $name)
    {
        $data = pack('H*', $octet);

        return $this->gamed->unmarshal($data, $this->data['octet'][$name]);
    }
}
