import {
  HPCoolingConfig,
  HPDefrostingConfig,
  HPGeneralConfig,
  HPHeatingConfig,
  HPWaterTankConfig,
  Mode,
  HeatPumpState,
  HeatPumpConfig,
  HeatPump,
} from '../../models/heatpump';
import routes from '../../utilities/routes';
import axios from '../axios';

export class HeatPumpApi {
  async get(): Promise<HeatPump> {
    const response = await axios.get(routes.heatpump.get);
    return await response.data;
  }

  async getState(): Promise<HeatPumpState> {
    const response = await axios.get(routes.heatpump.getState);
    return response.data;
  }

  /* ----------------------- */
  /* Heat pump configuration */
  /* ----------------------- */
  async getConfig(): Promise<HeatPumpConfig> {
    const response = await axios.get(routes.heatpump.getConfig);
    return response.data;
  }

  /** Patch request to set heat pump operating mode */
  async setMode(data: Mode): Promise<Mode> {
    const response = await axios.patch(routes.heatpump.setMode, data);
    return await response.data;
  }

  /** Patch request to update heat pump general configuration */
  async updateGeneralConfiguration(data: HPGeneralConfig): Promise<void> {
    const response = await axios.patch(routes.heatpump.updateHeatingConfiguration, data);
    return await response.data;
  }

  /** Patch request to update heat pump heating mode configuration */
  async updateHeatingConfiguration(data: HPHeatingConfig): Promise<void> {
    const response = await axios.patch(routes.heatpump.updateHeatingConfiguration, data);
    return await response.data;
  }

  /** Patch request to update heat pump water tank mode configuration */
  async updateWaterTankConfiguration(data: HPWaterTankConfig): Promise<void> {
    const response = await axios.patch(routes.heatpump.updateWaterTankConfiguration, data);
    return await response.data;
  }

  /** Patch request to update heat pump defrosting mode configuration */
  async updateDefrostingConfiguration(data: HPDefrostingConfig): Promise<void> {
    const response = await axios.patch(routes.heatpump.updateDefrostingConfiguration, data);
    return await response.data;
  }

  /** Patch request to update heat pump cooling mode configuration */
  async updateCoolingConfiguration(data: HPCoolingConfig): Promise<void> {
    const response = await axios.patch(routes.heatpump.updateCoolingConfiguration, data);
    return await response.data;
  }
}
