import { PlatformConfig } from "homebridge";

export interface IConfig extends PlatformConfig {
  refImageDirectory: string;
  trainedModelDirectory: string;
  weightDirectory: string;
  outputDirectory: string;
  trainOnStartup: boolean;
  rooms: Array<IRoom>;
  detectionTimeout: number;
  debug: boolean;
  writeOutput: boolean;
}

export interface IRoom {
  name: string;
  rtspConnectionStrings: Array<string>;
}

export const isRoom = (object: any): object is IRoom => {
  return "name" in object && "rtspConnectionStrings" in object;
};

export const isConfig = (object: any): object is IConfig => {
  const roomsOkay =
    object["rooms"].filter((room: any) => isRoom(room)).length ===
    object["rooms"].length;
  return (
    "refImageDirectory" in object &&
    "trainedModelDirectory" in object &&
    "weightDirectory" in object &&
    "outputDirectory" in object &&
    "trainOnStartup" in object &&
    "detectionTimeout" in object &&
    "writeOutput" in object &&
    "rooms" in object &&
    roomsOkay
  );
};
