import { Identify } from '@matter/main/clusters';
import { DimmableLightRequirements } from '@matter/node/devices';

import { Devices } from 'isy-nodejs/ISY';
import { BehaviorRegistry } from '../BehaviorRegistry.js';
import { ISYClusterBehavior } from '../ISYClusterBehavior.js';

export class IdentifyBehavior extends ISYClusterBehavior(DimmableLightRequirements.IdentifyServer, Devices.ZigBee.ExtendedColorLight) {
	override async initialize() {
		await super.initialize();
		this.state.identifyType = Identify.IdentifyType.AudibleBeep;
	}
	override async identify() {
		return this.device.onOff.identify();
	}

	override async triggerEffect(request: Identify.TriggerEffectRequest) {
		switch (request.effectIdentifier) {
			case Identify.EffectIdentifier.Blink:
				return this.device.onOff.fastOn().then(() => this.device.onOff.fastOff());
			default:
				return this.device.onOff.identify();
		}
	}
}

BehaviorRegistry.register(IdentifyBehavior);
