import * as v from "valibot";

export enum DeviceStatus {
    ONLINE = "online",
    OFFLINE = "offline",
    BUSY = "busy",
    ERROR = "error",
}

export const deviceStatusSchema = v.picklist(["online", "offline", "busy", "error"]);
export type DeviceStatusValue = v.InferOutput<typeof deviceStatusSchema>;

export const deviceSchema = v.object({
    id: v.number(),
    title: v.string(),
    version: v.string(),
    status: deviceStatusSchema,
    isActive: v.boolean(),
    inUse: v.boolean(),
    containerId: v.string(),
    host: v.string(),
    wsPort: v.string(),
    createdAt: v.date(),
    updatedAt: v.date(),
});
export type Device = v.InferOutput<typeof deviceSchema>;

export const createDeviceSchema = v.object({
    title: v.pipe(v.string(), v.minLength(1)),
    version: v.pipe(v.string(), v.minLength(1)),
    host: v.pipe(v.string(), v.minLength(1)),
    containerId: v.pipe(v.string(), v.minLength(1)),
    wsPort: v.pipe(v.string(), v.minLength(1)),
    isActive: v.optional(v.boolean()),
});
export type CreateDevice = v.InferOutput<typeof createDeviceSchema>;

export const updateDeviceSchema = v.partial(
    v.object({
        title: v.string(),
        version: v.string(),
        host: v.string(),
        containerId: v.string(),
        wsPort: v.string(),
        isActive: v.boolean(),
        inUse: v.boolean(),
        status: deviceStatusSchema,
    }),
);
export type UpdateDevice = v.InferOutput<typeof updateDeviceSchema>;
