import { z } from 'zod';

export const idleStatusResponseSchema = z.object({
  enabled: z.boolean(),
  playerCount: z.number().int().nullable(),
  idleStopAt: z.string().datetime().nullable(),
  secondsRemaining: z.number().int().nullable(),
  lastPlayerSeenAt: z.string().datetime().nullable(),
});

export const creditTransactionSchema = z.object({
  id: z.string().uuid(),
  amount: z.number().int(),
  type: z.enum(['GRANT', 'USAGE_DEBIT', 'ADJUSTMENT', 'EXPIRE']),
  referenceType: z.string().nullable(),
  referenceId: z.string().nullable(),
  createdAt: z.string().datetime(),
});

export const walletResponseSchema = z.object({
  balance: z.number().int(),
  periodStart: z.string().datetime(),
  transactions: z.array(creditTransactionSchema),
});

export const usageRecordSchema = z.object({
  id: z.string().uuid(),
  serverId: z.string().uuid(),
  ramMb: z.number().int(),
  durationSeconds: z.number().int(),
  creditsCharged: z.number().int(),
  periodStart: z.string().datetime(),
  periodEnd: z.string().datetime(),
  createdAt: z.string().datetime(),
});

export const usageListResponseSchema = z.object({
  records: z.array(usageRecordSchema),
});

export type IdleStatusResponse = z.infer<typeof idleStatusResponseSchema>;
export type WalletResponse = z.infer<typeof walletResponseSchema>;
export type UsageListResponse = z.infer<typeof usageListResponseSchema>;
