import type { MaybePromise } from '@matter/general';
import type { LevelControl } from '@matter/main/clusters';
import { DimmableLightRequirements } from '@matter/node/devices';
import type { BitFlag, TypeFromPartialBitSchema } from '@matter/types';
import { Devices } from 'isy-nodejs/ISY';
import { BehaviorRegistry } from '../BehaviorRegistry.js';
import { ISYClusterBehavior } from '../ISYClusterBehavior.js';

export class DimmerLevelControlBehavior extends ISYClusterBehavior(DimmableLightRequirements.LevelControlServer, Devices.ZigBee.ExtendedColorLight) {
	override async initialize(_options?: {}): Promise<void> {
		await super.initialize(_options);
		this.state.minLevel = 1;
		this.state.maxLevel = 254;
		this.state.currentLevel = this.state.onLevel ?? 254;
	}

	override async moveToLevelLogic(level: number, transitionTime: number | null, withOnOff: boolean, options: TypeFromPartialBitSchema<{ executeIfOff: BitFlag; coupleColorTempToLevel: BitFlag }>) {
		await this.device.onOff.on(level, transitionTime);
		await super.moveToLevelLogic(level, transitionTime, withOnOff, options);
	}
	/*override async setLevel(level: number): Promise<void> {
		if(level == this.state.maxLevel && this.state.currentLevel == this.state.minLevel) //If the light is off and we are setting it to max, set it to onLevel
		{
			await this.device.onOff.on(level,
			this.state.currentLevel = this.state.onLevel;
		}
		else
		{
			return super.setLevel(level);
		}
	}*/
}

BehaviorRegistry.register(DimmerLevelControlBehavior);
