import type { ProviderDescriptor } from './types';

export const nutDescriptor: ProviderDescriptor = {
	type: 'nut',
	defaultName: 'NUT',
	icon: 'mdiBatteryCharging80',
	hasUrl: false,

	configFields: [
		{
			key: 'nut_host', configKey: 'host',
			label: 'providers.nutHost', type: 'text',
			required: true, placeholder: '192.168.1.100 or ups.local',
		},
		{
			key: 'nut_port', configKey: 'port',
			label: 'providers.nutPort', type: 'number',
			min: 1, max: 65535, defaultValue: 3493,
		},
		{
			key: 'nut_username', configKey: 'username',
			label: 'providers.nutUsername', type: 'text',
			optional: true, hint: 'providers.nutUsernameHint',
		},
		{
			key: 'nut_password', configKey: 'password',
			label: 'providers.nutPassword', type: 'password',
			optional: true, hint: 'providers.nutPasswordHint',
		},
	],

	buildConfig(form) {
		const config: Record<string, any> = {
			host: form.nut_host,
			port: form.nut_port || 3493,
		};
		if (form.nut_username) config.username = form.nut_username;
		if (form.nut_password) config.password = form.nut_password;
		return { config };
	},

	hasConfigChanged() {
		// NUT fields are always sent (no secret masking)
		return true;
	},

	eventFields: [
		{ key: 'track_ups_online', label: 'trackingConfig.upsOnline', default: true },
		{ key: 'track_ups_on_battery', label: 'trackingConfig.upsOnBattery', default: true },
		{ key: 'track_ups_low_battery', label: 'trackingConfig.upsLowBattery', default: true },
		{ key: 'track_ups_battery_restored', label: 'trackingConfig.upsBatteryRestored', default: true },
		{ key: 'track_ups_comms_lost', label: 'trackingConfig.upsCommsLost', default: true },
		{ key: 'track_ups_comms_restored', label: 'trackingConfig.upsCommsRestored', default: true },
		{ key: 'track_ups_replace_battery', label: 'trackingConfig.upsReplaceBattery', default: true },
		{ key: 'track_ups_overload', label: 'trackingConfig.upsOverload', default: true },
	],

	collectionMeta: {
		label: 'notificationTracker.upsDevices',
		icon: 'mdiBatteryCharging80',
		placeholder: 'notificationTracker.selectUpsDevices',
		countLabel: 'notificationTracker.devices_count',
		desc: (col) => col.description || '',
	},
};
