import type { BaseComponentDiscovery } from './BaseEntityDiscovery.ts';
import {MakeEntity} from './utils';

/**
 * @see https://www.home-assistant.io/integrations/image.mqtt/
 */
export type ImageDiscovery = UrlImageDiscovery | TopicImageDiscovery;

/**
 * @see https://www.home-assistant.io/integrations/image.mqtt/
 */
export type ImageComponentDiscovery = UrlImageComponentDiscovery | TopicImageComponentDiscovery;

export interface UrlImageComponentDiscovery extends BaseComponentDiscovery {
	platform: 'image';

	/**
	 * Defines a template to extract the image URL from a message received at url_topic.
	 */
	url_template?: string;

	/**
	 * The MQTT topic to subscribe to receive an image URL. 
	 * A url_template option can extract the URL from the message. 
	 * The content_type will be derived from the image when downloaded. 
	 * This option cannot be used together with the image_topic option, but at least one of these options is required.
 	*/
	url_topic?: string;
}

export type UrlImageDiscovery = MakeEntity<UrlImageComponentDiscovery>;

export interface TopicImageComponentDiscovery extends BaseComponentDiscovery {
	platform: 'image';

	/**
	 * The content type of and image data message received on image_topic. 
	 * This option cannot be used with the url_topic because the content type is derived when downloading the image.
	 * @defaultValue image/jpeg
	 */
	content_type?: string;

	/**
	 * The encoding of the image payloads received. 
	 * Set to "b64" to enable base64 decoding of image payload. 
	 * If not set, the image payload must be raw binary data.
	 * @defaultValue None
	 */
	image_encoding?: 'b64';
	

	/**
	 * The MQTT topic to subscribe to receive the image payload of the image to be downloaded.
	 * Ensure the content_type type option is set to the corresponding content type.
	 * This option cannot be used together with the url_topic option. But at least one of these option is required.
	 */
	image_topic?: string;
}

export type TopicImageDiscovery = MakeEntity<TopicImageComponentDiscovery>;