import type { Request, Response } from "express";
import { z } from "zod";
import * as syncService from "./service.js";

const pushSchema = z.object({
  locations: z.array(z.any()).optional(),
  players: z.array(z.any()).optional(),
  sessions: z.array(z.any()).optional(),
});

export async function pull(req: Request, res: Response) {
  const since = Number(req.query.since) || 0;
  const result = await syncService.pull(req.userId!, since);
  res.json(result);
}

export async function push(req: Request, res: Response) {
  const payload = pushSchema.parse(req.body);
  const result = await syncService.push(req.userId!, payload);
  res.json(result);
}
