<?php
/**
 * sync-user-activity (hourly)
 *
 * Ships the bounded recent-activity log (capped at 50 per user). Uses the
 * synced_at lifecycle so each row goes exactly once.
 */

if (!defined('ABSPATH')) exit;

require_once __DIR__ . '/class-sync-base.php';

class AF_Activity_Sync extends AF_Sync_Base {

    protected $endpoint     = 'sync-user-activity';
    protected $cron_hook    = 'auctionforge_sync_user_activity';
    protected $cron_schedule = 'hourly';
    protected $batch_size   = 500;
    protected $health_key   = 'user-activity';

    public function __construct() {
        global $wpdb;
        $this->table = $wpdb->prefix . 'af_user_recent_activity';
    }

    protected function read_batch() {
        global $wpdb;
        if (!$this->table_exists($this->table)) return array();

        return $wpdb->get_results($wpdb->prepare(
            "SELECT * FROM {$this->table} WHERE synced_at IS NULL ORDER BY id ASC LIMIT %d",
            $this->batch_size
        ), ARRAY_A);
    }

    protected function build_payload($rows) {
        return array('records' => $rows);
    }
}
