<?php

declare(strict_types=1);

namespace PhpWA\AppState;

use InvalidArgumentException;

final class AppStateExpandedKeys
{
    /** @var string */ private $index;
    /** @var string */ private $valueEncryption;
    /** @var string */ private $valueMac;
    /** @var string */ private $snapshotMac;
    /** @var string */ private $patchMac;

    public function __construct(string $expanded)
    {
        if (strlen($expanded) !== 160) { throw new InvalidArgumentException('Expanded app-state keys must contain 160 bytes.'); }
        $this->index = substr($expanded, 0, 32);
        $this->valueEncryption = substr($expanded, 32, 32);
        $this->valueMac = substr($expanded, 64, 32);
        $this->snapshotMac = substr($expanded, 96, 32);
        $this->patchMac = substr($expanded, 128, 32);
    }

    public function index(): string { return $this->index; }
    public function valueEncryption(): string { return $this->valueEncryption; }
    public function valueMac(): string { return $this->valueMac; }
    public function snapshotMac(): string { return $this->snapshotMac; }
    public function patchMac(): string { return $this->patchMac; }
}
