// Contains definitions specific to meters.
//
// Copyright:
// Copyright 2022 Frequenz Energy-as-a-Service GmbH
//
// License:
// MIT

syntax = "proto3";

package frequenz.api.microgrid.meter;

import "frequenz/api/microgrid/common.proto";

// Enumerated meter types.
enum Type {
  TYPE_UNSPECIFIED = 0;

  // AC production power meter / inverter production AC power (fallback)
  TYPE_PRODUCTION = 1;

  // Consumption meter
  TYPE_CONSUMPTION = 2;

  // Exported to grid meter
  TYPE_FEED_IN = 3;

  // Imported power from grid meter
  TYPE_PURCHASED = 4;
}

// Enumerated meter states.
enum ComponentState {
  // Unspecified state.
  COMPONENT_STATE_UNSPECIFIED = 0;

  // The meter is behaving as expected.
  COMPONENT_STATE_OK = 1;

  // The meter is in an error state.
  COMPONENT_STATE_ERROR = 2;
}

// Enumerated meter error codes.
enum ErrorCode {
  // Unspecified.
  ERROR_CODE_UNSPECIFIED = 0;
}

// State message.
message State {
  // The state of the overall component.
  ComponentState component_state = 1;
}

// Error message.
message Error {
  // The error code.
  ErrorCode code = 1;

  // The error severity level.
  common.ErrorLevel level = 2;

  // The error message.
  string msg = 3;
}

// Meter data.
message Data {
  // AC metrics of the inverter.
  common.AC ac = 1;
}

// Meter properties.
message Properties {
  // The firmware version of the component.
  string firmware_ver = 1;
}

// Meter details
message Meter {
  // The component properties
  Properties properties = 1;

  // The meter's state.
  State state = 2;

  // A list of errors encountered the component. An empty list implies no error.
  repeated Error errors = 3;

  // A meter data object.
  Data data = 4;
}
