interface AssetEventSchema {
    modelUuid: string;
    modelName: string;
    position: [number, number, number];
    rotation: [number, number, number];
    state: "idle" | "running" | "stopped" | "disabled" | "error";
}

interface TriggerSchema {
    triggerUuid: string;
    triggerName: string;
    triggerType: "onComplete" | "onStart" | "onStop" | "delay" | "onError";
    delay: number;
    triggeredAsset: {
        triggeredModel: { modelName: string, modelUuid: string };
        triggeredPoint: { pointName: string, pointUuid: string } | null;
        triggeredAction: { actionName: string, actionUuid: string } | null;
    } | null;
}

interface ConveyorPointSchema {
    uuid: string;
    position: [number, number, number];
    rotation: [number, number, number];
    action: ConveyorAction;
}

interface VehiclePointSchema {
    uuid: string;
    position: [number, number, number];
    rotation: [number, number, number];
    action: VehicleAction;
}

interface RoboticArmPointSchema {
    uuid: string;
    position: [number, number, number];
    rotation: [number, number, number];
    actions: RoboticArmAction[];
}

interface MachinePointSchema {
    uuid: string;
    position: [number, number, number];
    rotation: [number, number, number];
    action: MachineAction;
}

interface StoragePointSchema {
    uuid: string;
    position: [number, number, number];
    rotation: [number, number, number];
    action: StorageAction;
}

interface ConveyorEventSchema extends AssetEventSchema {
    type: "transfer";
    speed: number;
    points: ConveyorPointSchema[];
}

interface VehicleEventSchema extends AssetEventSchema {
    type: "vehicle";
    speed: number;
    point: VehiclePointSchema;
}

interface RoboticArmEventSchema extends AssetEventSchema {
    type: "roboticArm";
    speed: number;
    point: RoboticArmPointSchema;
}

interface MachineEventSchema extends AssetEventSchema {
    type: "machine";
    point: MachinePointSchema;
}

interface StorageEventSchema extends AssetEventSchema {
    type: "storageUnit";
    point: StoragePointSchema;
}

interface ConveyorAction {
    actionUuid: string;
    actionName: string;
    actionType: "default" | "spawn" | "swap" | "delay" | "despawn";
    material: string;
    delay: number;
    spawnInterval: number;
    spawnCount: number;
    triggers: TriggerSchema[];
}

interface VehicleAction {
    actionUuid: string;
    actionName: string;
    actionType: "travel";
    unLoadDuration: number;
    loadCapacity: number;
    steeringAngle: number;
    pickUpPoint: { position: { x: number; y: number, z: number }, rotation: { x: number; y: number, z: number } } | null;
    unLoadPoint: { position: { x: number; y: number, z: number }, rotation: { x: number; y: number, z: number } } | null;
    triggers: TriggerSchema[];
}

interface RoboticArmAction {
    actionUuid: string;
    actionName: string;
    actionType: "pickAndPlace";
    process: { startPoint: [number, number, number] | null; endPoint: [number, number, number] | null; };
    triggers: TriggerSchema[];
}

interface MachineAction {
    actionUuid: string;
    actionName: string;
    actionType: "process";
    processTime: number;
    swapMaterial: string;
    triggers: TriggerSchema[];
}

interface StorageAction {
    actionUuid: string;
    actionName: string;
    actionType: "store";
    storageCapacity: number;
    triggers: TriggerSchema[];
}

type Action = ConveyorAction | VehicleAction | RoboticArmAction | MachineAction | StorageAction;

type PointsScheme = ConveyorPointSchema | VehiclePointSchema | RoboticArmPointSchema | MachinePointSchema | StoragePointSchema;

type EventsSchema = ConveyorEventSchema | VehicleEventSchema | RoboticArmEventSchema | MachineEventSchema | StorageEventSchema;

type productsSchema = {
    productName: string;
    productId: string;
    eventDatas: EventsSchema[];
}[]


interface ConveyorStatus extends ConveyorEventSchema {
    productId: string;
    isActive: boolean;
    isPaused: boolean;
    idleTime: number;
    activeTime: number;
}

interface MachineStatus extends MachineEventSchema {
    productId: string;
    isActive: boolean;
    idleTime: number;
    activeTime: number;
    currentAction?: {
        actionUuid: string;
        actionName: string;
        materialType: string | null;
    };
}

interface ArmBotStatus extends RoboticArmEventSchema {
    productId: string;
    isActive: boolean;
    idleTime: number;
    activeTime: number;
    currentAction?: {
        actionUuid: string;
        actionName: string;
        materialType: string | null;
        materialId: string | null;
    };
}

interface VehicleStatus extends VehicleEventSchema {
    productId: string;
    isActive: boolean;
    idleTime: number;
    activeTime: number;
    currentLoad: number;
    currentMaterials: { materialType: string; materialId: string; }[];
    distanceTraveled: number;
}

interface StorageUnitStatus extends StorageEventSchema {
    productId: string;
    isActive: boolean;
    idleTime: number;
    activeTime: number;
    currentLoad: number;
    materials?: { materialName: string; materialId: string; }[];
}

interface MaterialSchema {
    materialId: string;
    materialName: stri9ng;
    materialType: string;
    isActive: boolean;
    isVisible: boolean;
    isPaused: boolean;
    isRendered: boolean;
    startTime?: number;
    endTime?: number;
    cost?: number;
    weight?: number;

    previous?: {
        modelUuid: string;
        pointUuid: string;
        actionUuid: string;
    };

    current: {
        modelUuid: string;
        pointUuid: string;
        actionUuid: string;
    };

    next?: {
        modelUuid: string;
        pointUuid: string;
    } | null;
}

type MaterialsSchema = MaterialSchema[];

interface MaterialHistoryEntry {
    material: MaterialSchema;
    removedAt: string;
}

type MaterialHistorySchema = MaterialHistoryEntry[];