<?php

namespace App\Media\MSVideo\Containers\rlist;

use Illuminate\Support\Arr;

use App\Media\MSVideo\Container;

class avih extends Container
{
	protected const unpack = [
		'tbframe'=>['V',4],
		'mdr'=>['V',4],
		'PG'=>['V',4],
		'flags'=>['V',4],
		'frames'=>['V',4],
		'init_frames'=>['V',4],
		'streams'=>['V',4],
		'buffer_size'=>['V',4],
		'width'=>['V',4],
		'height'=>['V',4],
		'time_scale'=>['V',4],
		'data_rate'=>['V',4],
		'start_time'=>['V',4],
		'data_length'=>['V',4],
	];

	public function __construct(int $offset,int $size,string $filename,bool $be,?string $data)
	{
		parent::__construct($offset,$size,$filename,$be,$data);

		$this->cache = $this->cache($data);

		// For debugging
		if (FALSE)
			$this->debug = hex_dump($data ?: $this->data());
	}

	public function __get(string $key): mixed
	{
		switch ($key) {
			case 'height':
			case 'width':
				return Arr::get($this->cache,$key);

			default:
				return parent::__get($key);
		}
	}
}