<?php
declare(strict_types=1);
namespace app\common\service { class BaseService {protected $storeId=10001;public function __construct(){$this->initialize();}} }
namespace app\p\logic { class AccountSettingPolicy {} }
namespace think { class Db {public static function name($table){$GLOBALS['staff_builder_calls']++;return new \DateQuery($GLOBALS['staffDb'],$table);}} }
namespace {
date_default_timezone_set('Asia/Shanghai');
$main=$argv[1];$file=$argv[2];require $main.'/application/common/service/account/GiftFlowRead.php';
class DateDb {public $type;public $events=[];public $rows=[];public $typeCalls=0;public function __construct($type){$this->type=$type;}public function name($table){return new DateQuery($this,$table);}public function getConfig($key){if($key!=='type')throw new \RuntimeException('Only actual AI connection type');$this->typeCalls++;return $this->type;}}
class DatePage {private $value;public function __construct($value){$this->value=$value;}public function toArray(){return $this->value;}}
class DateQuery {private $db;private $table;private $where=[];private $fields='';public function __construct($db,$table){$this->db=$db;$this->table=$table;}public function where($a,$b=null,$c=null){if(is_array($a))$this->where=array_merge($this->where,$a);else $this->where[$a]=[$b,$c];return $this;}public function whereIn($field,$values){$this->where[$field]=['in',$values];return $this;}public function field($fields){$this->fields=$fields;return $this;}public function order($order){return $this;}public function paginate($size,$simple,$options){$this->db->events[]=['operation'=>'paginate','where'=>$this->where,'fields'=>$this->fields];return new DatePage(['total'=>count($this->db->rows),'per_page'=>$size,'current_page'=>$options['page'],'last_page'=>count($this->db->rows)?1:0,'data'=>$this->db->rows]);}public function sum($field){$this->db->events[]=['operation'=>'sum','where'=>$this->where,'field'=>$field];return '0.00';}public function select(){return [['ai_user_id'=>42,'name'=>'fixture-name','mobile'=>'fixture-mobile']];}public function column($field){return [42];}}
function get_ai_db(){$GLOBALS['ai_getter_calls']++;return $GLOBALS['aiDb'];}
function config($key){$GLOBALS['global_config_calls']++;return $GLOBALS['store_global_type'];}
require $file;
$count=0;$failures=[];$check=static function($ok,$why)use(&$count,&$failures){$count++;if(!$ok)$failures[]=$why;};
$run=static function($type,$params,$globalType,$withRow=false)use($check){
 $GLOBALS['aiDb']=new DateDb($type);$GLOBALS['staffDb']=new DateDb('store');$GLOBALS['ai_getter_calls']=0;$GLOBALS['staff_builder_calls']=0;$GLOBALS['global_config_calls']=0;$GLOBALS['store_global_type']=$globalType;
 if($withRow){$dm=ltrim((string)$type,'\\')==='app\\cores\\database\\Dm';$row=['log_id'=>7,'user_id'=>42,'scene'=>30,'money'=>'0.00','balance_before'=>'20.00','balance_after'=>'20.00','biz_type'=>'fixture','biz_order_id'=>$dm?9007199254740992.0:9007199254740993,'biz_order_no'=>'CDXGW11B6A91C-2','describe'=>'fixture','remark'=>'fixture','operator_name'=>'fixture','create_time'=>$dm?'2001-01-01 00:00:00.000000':978278400];if($dm)$row['gift_biz_order_id_exact']='9007199254740993';$GLOBALS['aiDb']->rows=[$row];}
 $error=null;$result=null;try{$result=(new \app\p\logic\AccountSetting())->giftFlowList($params);}catch(\Throwable $e){$error=$e;}
 return ['db'=>$GLOBALS['aiDb'],'calls'=>$GLOBALS['ai_getter_calls'],'global_calls'=>$GLOBALS['global_config_calls'],'staff_calls'=>$GLOBALS['staff_builder_calls'],'result'=>$result,'error'=>$error];
};
$types=['mysql','MYSQL','\\app\\cores\\database\\Dm','app\\cores\\database\\Dm','other',null];
foreach($types as $type){
 foreach([[],['start_date'=>'2001-01-01'],['end_date'=>'2001-01-01'],['start_date'=>'not-a-date','end_date'=>'']]as $params){$got=$run($type,$params,'wrong-store-type');$check($got['error']===null,'No/single date original acceptance');$check($got['calls']===1,'No/single date AI getter once');$check($got['global_calls']===0,'No global Store database.type');$check(count($got['db']->events)===3,'No/single original 1paginate+2SUM');foreach($got['db']->events as $event)$check(!isset($event['where']['create_time']),'No/single no date predicate');}
 foreach([['start_date'=>'not-a-date','end_date'=>'2001-01-01'],['start_date'=>'2001-01-03','end_date'=>'2001-01-01']]as $params){$got=$run($type,$params,'wrong-store-type');$check($got['error'] instanceof \InvalidArgumentException&&$got['error']->getMessage()==='流水日期范围不正确','Invalid original exception/message');$check($got['calls']===0&&$got['staff_calls']===0&&$got['db']->events===[],'Invalid before getter/SQL');}
 $params=['start_date'=>'2001-01-01','end_date'=>'2001-01-01','biz_order_no'=>'CDXGW11B6A91C'];$got=$run($type,$params,$type==='mysql'?'\\app\\cores\\database\\Dm':'mysql',true);$check($got['error']===null,'Valid branch/hidden projection executes');$check($got['calls']===1,'Valid AI getter exactly1');$check($got['global_calls']===0,'Actual AI type wins inverse Store global type');$check(count($got['db']->events)===3,'Valid paginate+2SUM');$expected=['between',strtolower((string)$type)==='mysql'?[978278400,978364799]:['2001-01-01 00:00:00','2001-01-01 23:59:59']];foreach($got['db']->events as $event)$check($event['where']['create_time']===$expected,'Actual bound condition type across rows/count paginate and both SUM '.(string)$type);
 $dto=$got['result']['data'][0]??[];$check(($dto['biz_order_id']??null)===9007199254740993,'Wide reference exact original int');$check(!array_key_exists('gift_biz_order_id_exact',$dto),'Hidden projection never leaks');$check(($dto['create_time']??null)==='2001-01-01 00:00:00','Existing account timestamp output');$check(($dto['nickname']??null)==='fixture-name'&&($dto['mobile']??null)==='fixture-mobile','Original Staff DTO');$check($got['result']['income_amount']==='0.00'&&$got['result']['expense_amount']==='0.00','Money outputs untouched');
 $field=$got['db']->events[0]['fields'];$dm=ltrim((string)$type,'\\')==='app\\cores\\database\\Dm';$check((strpos($field,'gift_biz_order_id_exact')!==false)===$dm,'Existing DM-only exact projection unchanged');
}
echo json_encode(['assertions'=>$count,'failures'=>count($failures),'passed'=>$failures===[],'failed_assertions'=>$failures,'PDO'=>0,'SQL'=>0,'HTTP'=>0],JSON_UNESCAPED_UNICODE),"\n";
exit($failures===[]?0:1);
}
