Files
Investidor-V2/app/Models/SimulationFormDraft.php
nala e65cb26901
tests / ci (push) Canceled after 0s
varias alteracoes
2026-10-06 14:50:12 +02:00

57 lines
1.7 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Crypt;
/**
* @property string $id
* @property int|null $owner_user_id
* @property string|null $anonymous_token_hash
* @property int $version_no
* @property string $create_key_hash
* @property string $create_payload_hash
* @property string $snapshot_sha256
* @property string $personal_snapshot
* @property string $economic_snapshot
* @property Carbon|null $deleted_at
* @property Carbon|null $expires_at
* @property string|null $claimed_token_hash
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
*/
class SimulationFormDraft extends Model
{
public $incrementing = false;
protected $table = 'simulation_form_drafts';
protected $keyType = 'string';
protected $fillable = [
'id', 'owner_user_id', 'anonymous_token_hash', 'version_no', 'create_key_hash', 'create_payload_hash', 'snapshot_sha256',
'personal_snapshot', 'economic_snapshot', 'deleted_at', 'expires_at', 'claimed_token_hash',
];
protected function casts(): array
{
return ['version_no' => 'integer', 'deleted_at' => 'immutable_datetime', 'expires_at' => 'immutable_datetime'];
}
/** @param array<string,mixed> $snapshot */
public static function encryptSnapshot(array $snapshot): string
{
return Crypt::encryptString(json_encode($snapshot, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
}
/** @return array<string,mixed> */
public static function decryptSnapshot(string $snapshot): array
{
$decoded = json_decode(Crypt::decryptString($snapshot), true, 32, JSON_THROW_ON_ERROR);
return is_array($decoded) ? $decoded : [];
}
}