package monitor

import (
	"server/dao/devices"
	"server/global"
	"server/model/monitor"
)

type CommonService struct{}

func (s CommonService) DevicesCameras() ([]monitor.CameraTree, error) {
	intersect := devices.Intersect{}
	intersectList, _ := intersect.PublicIntersect()

	camera := devices.Camera{}
	list, _ := camera.GetCameraTree()

	var rsp []monitor.CameraTree
	for _, luk := range intersectList {
		var cameraList []monitor.CameraDev
		for _, cam := range list {
			if cam.GateWay.Intersect.ID == luk.ID {
				poleGroupName := cam.CameraName + "(在线)"
				if cam.Status == 1 {
					poleGroupName = cam.CameraName + "(离线)"
				}
				devAddress := luk.Address + "--" + cam.ShuntDescribe + "(主路)"
				if cam.Shunt == 2 {
					devAddress = luk.Address + "--" + cam.ShuntDescribe + "(支路)"
				}
				cameraList = append(cameraList, monitor.CameraDev{
					Id:            cam.ID,
					PoleGroupName: poleGroupName,
					DeviceName:    cam.CameraName,
					DeviceAddress: devAddress,
					DeviceCode:    cam.CameraCode,
					Status:        cam.Status,
					StreamAddress: global.GVA_CONFIG.Webrtc.Path + cam.StreamId,
					StreamId:      cam.StreamId,
				})
			}
		}
		rsp = append(rsp, monitor.CameraTree{
			PoleGroupName: luk.IntersectName,
			CameraList:    cameraList,
		})
	}
	return rsp, nil
}
