import { z } from "zod";

export const AssetRefSchema = z.object({
  source: z.string().default("unknown"),
  assetId: z.string().optional(),
  deviceId: z.string().optional(),
  name: z.string().optional()
});

export const ObservationSchema = z.object({
  assetRef: AssetRefSchema,
  metric: z.string(),
  schema_version: z.string().default("1.0"),
  value: z.union([z.string(), z.number(), z.boolean()]),
  ts: z.number(),
  unit: z.string().optional(),
  source: z.string().optional()
});

export const EventSchema = z.object({
  assetRef: AssetRefSchema,
  type: z.string(),
  schema_version: z.string().default("1.0"),
  ts: z.number(),
  payload: z.record(z.any()).optional()
});

export const TaskLogSchema = z.object({
  assetRef: AssetRefSchema,
  task: z.string(),
  schema_version: z.string().default("1.0"),
  status: z.string(),
  ts: z.number(),
  notes: z.string().optional()
});

export const InventoryMovementSchema = z.object({
  assetRef: AssetRefSchema,
  item: z.string(),
  schema_version: z.string().default("1.0"),
  quantity: z.number(),
  unit: z.string().optional(),
  direction: z.enum(["in", "out"]),
  ts: z.number()
});

export type AssetRef = z.infer<typeof AssetRefSchema>;
export type Observation = z.infer<typeof ObservationSchema>;
export type Event = z.infer<typeof EventSchema>;
export type TaskLog = z.infer<typeof TaskLogSchema>;
export type InventoryMovement = z.infer<typeof InventoryMovementSchema>;
