import { _objectSpread2 } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
//#region src/plus/saasDevice/devicePlanning/model/adapters.ts
/** 将后端按类型返回的 active_models 展平成去重后的型号列表。 */
const flattenDeviceModels = (types) => {
	const modelMap = /* @__PURE__ */ new Map();
	types.forEach((type) => {
		(type.active_models || []).forEach((model) => {
			if (!modelMap.has(model.code)) modelMap.set(model.code, _objectSpread2(_objectSpread2({}, model), {}, { type: model.type || type }));
		});
	});
	return Array.from(modelMap.values());
};
/** 把后端设备实体转换成列表和详情抽屉共用的展示模型。 */
const createDeviceRow = (item, translation, profileNameMap) => {
	var _item$type, _item$model, _item$profile;
	const name = translation(item.name);
	const typeName = translation((_item$type = item.type) === null || _item$type === void 0 ? void 0 : _item$type.name) || item.type_code;
	const modelName = translation((_item$model = item.model) === null || _item$model === void 0 ? void 0 : _item$model.name) || item.model_code;
	const link = item.link || "unlinked";
	const profileName = translation((_item$profile = item.profile) === null || _item$profile === void 0 ? void 0 : _item$profile.name) || (item.profile_id ? profileNameMap === null || profileNameMap === void 0 ? void 0 : profileNameMap.get(item.profile_id) : "") || (item.profile_id ? String(item.profile_id) : "-");
	return {
		id: item.id,
		name,
		typeName,
		modelName,
		profileName,
		link,
		status: item.type_kind === "dumb" ? item.status || "unknown" : link === "linked" ? item.status || "offline" : "unknown",
		structure: item.structure,
		typeCode: item.type_code,
		modelCode: item.model_code,
		_raw: item
	};
};
/** 兼容工作区详情接口可能返回 data 数组或单对象的两种结构。 */
const resolveWorkAreaDetail = (response) => {
	const data = response === null || response === void 0 ? void 0 : response.data;
	if (Array.isArray(data)) return data[0];
	return data || response;
};
/** 从工作区详情响应中提取三类设备数量，用于删除前阻断判断。 */
const getDeleteWorkAreaCounts = (response) => {
	const workArea = resolveWorkAreaDetail(response);
	return {
		smart: (workArea === null || workArea === void 0 ? void 0 : workArea.smart_devices_count) || 0,
		dumb: (workArea === null || workArea === void 0 ? void 0 : workArea.dumb_devices_count) || 0,
		integrated: (workArea === null || workArea === void 0 ? void 0 : workArea.integrated_devices_count) || 0
	};
};
//#endregion
export { createDeviceRow, flattenDeviceModels, getDeleteWorkAreaCounts };
