<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;

function Mirai_api_points_logs($db, $user) {
    if (!$user->hasLogin()) {
        return ['code' => 401, 'msg' => '请先登录', 'need_login' => true];
    }
    $uid = (int)$user->uid;
    $page = max(1, (int)($_POST['page'] ?? 1));
    $pageSize = min(50, max(1, (int)($_POST['pageSize'] ?? 20)));

    $result = Mirai_pointsGetLogs($uid, $page, $pageSize);

    $actionNames = [
        'sign_up' => '首次注册',
        'sign_in' => '每日登录',
        'post_new' => '发布文章',
        'post_like' => '文章获赞',
        'post_collect' => '文章被收藏',
        'comment_new' => '发表评论',
        'points_pay' => '积分支付',
        'purchase' => '购买' . Mirai_pointsName(),
        'exchange_vip' => '兑换会员',
        'refund' => '退回',
    ];

    foreach ($result['list'] as &$item) {
        $item['action_name'] = $actionNames[$item['action']] ?? $item['action'];
        $item['is_positive'] = $item['amount'] > 0;
    }

    return ['code' => 0, 'data' => $result];
}
