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


export type HVACModes = 'off' | 'heat' | 'cool' | 'auto' | 'dry' | 'fan_only';
/**
 * @see https://www.home-assistant.io/integrations/climate.mqtt/
 * */

export interface HVACComponentDiscovery extends BaseComponentDiscovery {
    platform: 'climate';
    /**
     * A template to render the value received on the `action_topic` with.
     */
    action_template?: string;

    /**
     * The MQTT topic subscribed for changes of the current action.
     * Valid values are `off`, 'heating', 'cooling', 'drying', 'idle', 'fan'.
     */
    action_topic?: string;

    /**
     * A template to render the value received on the `current_humidity_topic` with.
     */
    current_humidity_template?: string;

    /**
     * The MQTT topic subscribed for changes of the current humidity.
     * A "None" value will reset the current humidity.
     * Empty values will be ignored.
     */
    current_humidity_topic?: string;

    /**
     * A template to render the value received on the `current_temperature_topic` with.
     */
    current_temperature_template?: string;

    /**
     * The MQTT topic subscribed for changes of the current temperature.
     * A "None" value will reset the current temperature.
     * Empty values will be ignored.
     */
    current_temperature_topic?: string;

    /**
     * A template to render the value sent to the `fan_mode_command_topic` with.
     */
    fan_mode_command_template?: string;

    /**
     * The MQTT topic to publish commands to change the fan mode.
     */
    fan_mode_command_topic?: string;

    /**
     * A template to render the value received on the `fan_mode_state_topic` with.
     */
    fan_mode_state_template?: string;

    /**
     * The MQTT topic subscribed for changes of the fan mode.
     */
    fan_mode_state_topic?: string;

    /**
     * A list of available fan modes.
     * @defaultValue ['low', 'medium', 'high', 'auto']
     */
    fan_modes?: string[];

    /**
     * Set the initial target temperature. 
     * @defaultValue depends on the temperature unit, and will be 21 (Celsius) or 69.8 (Fahrenheit).
     */
    initial?: number;

    /**
     * The maximum target humidity percentage that can be set.
     * @defaultValue 99
     */
    max_humidity?: number;

    /**
     * The maximum target temperature.
     * @defaultValue depends on the temperature unit, and will be 35°C or 95°F.
     */ 
    max_temp?: number;

    /**
     * The minimum target humidity percentage that can be set.
     * @defaultValue 30
     */
    min_humidity?: number;

    /**
     * The minimum target temperature.
     * @defaultValue depends on the temperature unit, and will be 7°C or 44.6°F.
     */
    min_temp?: number;

    /**
     * A template to render the value sent to the `mode_command_topic` with.
     */
    mode_command_template?: string;

    /**
     * The MQTT topic to publish commands to change the mode.
     */
    mode_command_topic?: string;

    /**
     * A template to render the value received on the `mode_state_topic` with.
     */
    mode_state_template?: string;

    /**
     * The MQTT topic subscribed for changes of the mode.
     * If this is not set, the operation mode works in optimistic mode.
     */
    mode_state_topic?: string;

    /**
     * A list of available operation modes.
     * @defaultValue ['off', 'heat', 'cool', 'auto', 'dry', 'fan_only']
     */
    modes?: HVACModes[];

    /**
     * Flag that defines if the humidifier works in optimistic mode.
     * @defaultValue true if no state topic is set, otherwise false.
     */
    optimistic?: boolean;

    /**
     * Payload that represents the `off` state.
     * @defaultValue 'OFF'
     */
    payload_off?: string;

    /**
     * Payload that represents the `on` state.
     * @defaultValue 'ON'
     */
    payload_on?: string;

    /**
     * A template to render the value sent to the `power_command_topic` with. 
     * The valuee parameter is the payload set for `payload_on` or `payload_off`.
     */
    power_command_template?: string;

    /**
     * The MQTT topic to publish commands to change the HVAC power state. 
     * Sends the payload configured with payload_on if the climate is turned on via the climate.turn_on, 
     * or the payload configured with payload_off if the climate is turned off via the climate.turn_off service. 
     * Note that optimistic mode is not supported through climate.turn_on and climate.turn_off services. 
     * When called, these services will send a power command to the device but will not optimistically update the state of the climate entity.
     * The climate device should report its state back via mode_state_topic.
     */
    power_command_topic?: string;

    /**
     * The desired precision for this device.
     * Can be used to match your actual thermostat's precision.
     * Supported values are 0.1, 0.5 and 1.0.
     * @defaultValue 0.1 for Celsius, 1.0 for Fahrenheit
     */
    precision?: 0.1 | 0.5 | 1.0;

    preset_mode_command_template?: string;
    preset_mode_command_topic?: string;
    preset_mode_state_topic?: string;
    preset_mode_value_template?: string;
    preset_modes?: string[];

    swing_mode_command_template?: string;
    swing_mode_command_topic?: string;
    swing_mode_state_template?: string;
    swing_mode_state_topic?: string;
    swing_modes?: string[];

    target_humidity_command_template?: string;
    target_humidity_command_topic?: string;
    target_humidity_state_template?: string;
    target_humidity_state_topic?: string;

    temperature_command_template?: string;
    temperature_command_topic?: string;
    temperature_high_command_template?: string;
    temperature_high_command_topic?: string;
    temperature_high_state_template?: string;
    temperature_high_state_topic?: string;
    temperature_low_command_template?: string;
    temperature_low_command_topic?: string;
    temperature_low_state_template?: string;
    temperature_low_state_topic?: string;

    temperature_state_template?: string;
    temperature_state_topic?: string;

    temperature_unit?: 'C' | 'F';
    temp_step?: number;

    /**
     * Default template to render the payloads on all `*_state_topic`s with
     */
    value_template?: string;
}

export type HVACDiscovery = MakeEntity<HVACComponentDiscovery>;
