export type DriverKey = "adobe_connect" | "alocom" | "skyroom" | "fanotech";

export type DriverField = "base_url" | "username" | "password" | "api_token" | "folder_id";

export type DriverDef = {
  key: DriverKey;
  label: string;
  fields: DriverField[];
  baseUrl?: string;
};

export type OnlineClassProvider = {
  id: number;
  title: string;
  driver_key: string;
  base_url?: string | null;
  max_rooms?: number;
  active_rooms?: number;
  is_active?: boolean;
  status?: string;
  capabilities?: Record<string, boolean>;
  config?: Record<string, unknown> | null;
  branch_id?: number | null;
  branch_ids?: number[];
  branch?: { id: number; name: string } | null;
  creator?: { id: number; name: string } | null;
  can_manage?: boolean;
  has_credentials?: boolean;
};

export const ONLINE_CLASS_DRIVERS: DriverDef[] = [
  {
    key: "adobe_connect",
    label: "ادوبی کانکت",
    fields: ["base_url", "username", "password", "folder_id"],
  },
  {
    key: "alocom",
    label: "الوکام",
    fields: ["username", "password"],
    baseUrl: "https://pnlapi.alocom.co",
  },
  {
    key: "skyroom",
    label: "اسکای‌روم",
    fields: ["api_token"],
    baseUrl: "https://www.skyroom.online",
  },
  {
    key: "fanotech",
    label: "فنوتک",
    fields: ["api_token"],
    baseUrl: "https://fanotech.ir/api/v1",
  },
];

export const CAPABILITY_LABELS: Record<string, string> = {
  "rooms.create": "ساخت اتاق",
  "rooms.update": "ویرایش اتاق",
  "rooms.delete": "حذف اتاق",
  "participants.sync": "اعضا",
  "join.redirect_url": "لینک ورود",
  "join.sso_token": "ورود با توکن",
  "attendance.webhook": "حضور وب‌هوک",
  "attendance.poll": "حضور",
  "recordings.list": "ضبط",
  "host.lock_room": "قفل اتاق",
  "host.mute_all": "بی‌صدا کردن",
  "live.presence": "حضور زنده",
};

export function driverOf(key: string): DriverDef | undefined {
  return ONLINE_CLASS_DRIVERS.find((driver) => driver.key === key);
}

export function driverLabel(key: string): string {
  return driverOf(key)?.label ?? key;
}
