<?php
declare(strict_types=1);
function assertPageMetadata(array $g,bool $dm):void
{
    $c=[];foreach($g['columns'] as $v)$c[strtolower($v['column_name'])]=$v;
    $names=array_keys($c);sort($names);$expected=['page_id','page_type','page_name','page_data','store_id','is_delete','create_time','update_time'];sort($expected);
    if($names!==$expected||$g['foreign_keys']!==0||$g['triggers']!==0||$g['own_collision']!==0)throw new RuntimeException('Page exact metadata safe boundary');
    foreach(['page_id','page_type','store_id','is_delete','create_time','update_time'] as $k){$v=$c[$k];if(!in_array(strtolower($v['data_type']),['int','integer','bigint','tinyint','smallint'],true)||(int)($dm?$v['data_scale']:$v['numeric_scale'])!==0||($dm?$v['nullable']!=='N':$v['is_nullable']!=='NO'))throw new RuntimeException('Page numeric original column '.$k);}
    foreach(['page_type'=>'10','store_id'=>'0','is_delete'=>'0','create_time'=>'0','update_time'=>'0'] as $k=>$default)if(trim((string)($dm?$c[$k]['data_default']:$c[$k]['column_default']))!==$default)throw new RuntimeException('Page original default '.$k);
    if(strtolower($c['page_name']['data_type'])!=='varchar'||strtolower($c['page_data']['data_type'])!==($dm?'clob':'longtext'))throw new RuntimeException('Page original text/CLOB columns');
    if($dm){$ddl=$g['identity_columns'][0]['ddl']??'';if(!preg_match('/"PAGE_ID"\s+BIGINT\s+AUTO_INCREMENT\s+NOT NULL/i',$ddl)||!preg_match('/"PAGE_NAME"\s+VARCHAR\(255 CHAR\)/i',$ddl)||!preg_match('/PRIMARY KEY\("PAGE_ID"\)/i',$ddl))throw new RuntimeException('DM original identity PK/character bound');}
    else if($c['page_id']['extra']!=='auto_increment'||(int)$c['page_name']['character_maximum_length']!==255)throw new RuntimeException('MySQL original identity/character bound');
    $unique=[];foreach($g['indexes'] as $v){$isUnique=$dm?($v['uniqueness']==='UNIQUE'):((int)$v['non_unique']===0);if($isUnique)$unique[$v['index_name']][]=strtolower($v['column_name']);}if(!in_array(['page_id'],array_values($unique),true))throw new RuntimeException('Original unique PK index');
}
