<?php
/**
 * 바로빌 API 응답 raw 데이터 확인용 (디버그)
 */
header('Content-Type: application/json; charset=utf-8');

require_once('barobill_card_config.php');

try {
    $startDate = $_GET['startDate'] ?? date('Ymd', strtotime('-60 days'));
    $endDate = $_GET['endDate'] ?? date('Ymd');
    
    // SOAP 직접 호출
    global $barobillCardSoapClient, $barobillCertKey, $barobillCorpNum;
    
    $params = [
        'CERTKEY' => $barobillCertKey,
        'CorpNum' => $barobillCorpNum,
        'ID' => '',
        'CardNum' => '',
        'StartDate' => $startDate,
        'EndDate' => $endDate,
        'CountPerPage' => 10,
        'CurrentPage' => 1,
        'OrderDirection' => 2
    ];
    
    $result = $barobillCardSoapClient->GetPeriodCardApprovalLog($params);
    $resultData = $result->GetPeriodCardApprovalLogResult;
    
    // raw 데이터 출력
    $output = [
        'params' => $params,
        'resultKeys' => is_object($resultData) ? array_keys(get_object_vars($resultData)) : 'not object',
        'CurrentPage' => $resultData->CurrentPage ?? null,
        'MaxIndex' => $resultData->MaxIndex ?? null
    ];
    
    // CardLogList 확인
    if (isset($resultData->CardLogList)) {
        $output['CardLogListKeys'] = is_object($resultData->CardLogList) ? array_keys(get_object_vars($resultData->CardLogList)) : 'not object';
        
        if (isset($resultData->CardLogList->CardApprovalLog)) {
            $logs = $resultData->CardLogList->CardApprovalLog;
            if (!is_array($logs)) {
                $logs = [$logs];
            }
            
            if (!empty($logs)) {
                $firstLog = $logs[0];
                $output['firstLogKeys'] = is_object($firstLog) ? array_keys(get_object_vars($firstLog)) : 'not object';
                $output['firstLogData'] = $firstLog;
            }
        }
    }
    
    echo json_encode($output, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
    
} catch (Exception $e) {
    echo json_encode([
        'error' => $e->getMessage()
    ], JSON_UNESCAPED_UNICODE);
}
?>

