import { CameraGroupListTypeBackEnd, Camera } from '../type';
import { getVideoRenderUrlKey } from '../utils';

export function parseCameraGroupChildren(groupListBackEnd: CameraGroupListTypeBackEnd) {
  const groupList = groupListBackEnd as any;
  for (const group of groupList) {
    const newChildren: Camera[] = [];
    group.children.map((x) => {
      const cameraInfo = {} as Camera;
      cameraInfo['id'] = x['id'];
      cameraInfo['code'] = x['code'];
      cameraInfo['name'] = x['name'];
      cameraInfo.imageUrl = x.pushStreamDTO['imageUrl'];
      // cameraInfo.tenantId = x.tenantId;
      try {
        cameraInfo['url'] = x.pushStreamDTO['videoUrls'][getVideoRenderUrlKey()];
      } catch (error) {
        cameraInfo['url'] = '';
      }
      newChildren.push(cameraInfo as Camera);
    });
    group.children = newChildren;
  }

  return groupList;
}
