# Class PumpStateRepository

Namespace
  adas_core.Infrastructure.Repositories

Assembly
  adas-core.Infrastructure.dll

Provides a repository implementation for PumpState entities backed by a MongoDB data store.

    public class PumpStateRepository : MongoRepository<PumpState>, IMongoRepository<PumpState>, IPumpStateRepository

Inheritance
  object
  MongoRepository<PumpState>
  PumpStateRepository

Implements
  IMongoRepository<PumpState>
  IPumpStateRepository

Inherited Members
  MongoRepository<PumpState>.Db
  MongoRepository<PumpState>.Collection
  MongoRepository<PumpState>.InsertOneAsync(PumpState)
  MongoRepository<PumpState>.UpdateOneAsync(ObjectId, PumpState)
  MongoRepository<PumpState>.DeleteAsync(ObjectId)
  MongoRepository<PumpState>.InsertInitialLoad()
  MongoRepository<PumpState>.InsertManyAsync(List<PumpState>)
  MongoRepository<PumpState>.UpdateManyObjectIdAsync(string, ObjectId, ObjectId)
  MongoRepository<PumpState>.DeleteAsync(string)
  MongoRepository<PumpState>.CollectionExists(string)
  object.Equals(object)
  object.Equals(object, object)
  object.GetHashCode()
  object.GetType()
  object.MemberwiseClone()
  object.ReferenceEquals(object, object)
  object.ToString()

Extension Methods
  NumberUtils.IsNumber(object)
  NumberUtils.ToDouble(object)
  ObjectUtils.ToStr(object?)

## Remarks

Inherits base functionality from MongoRepository<T> and implements the IPumpStateRepository contract.

## Constructors

### PumpStateRepository(IOptions<ApiSettings>, IMongoDatabase)

    public PumpStateRepository(IOptions<ApiSettings> apiSettings, IMongoDatabase database)

#### Parameters

`apiSettings` IOptions<ApiSettings>
`database` IMongoDatabase

## Methods

### CreateIndexes()

Creates the indexes required for the collection. The base implementation is a no-op; derived classes should override this method to define their own indexes.

    public override Task CreateIndexes()

#### Returns

Task

  A Task representing the asynchronous index creation operation.

### FindByDeviceIdAsync(string)

Retrieves the pump state associated with the specified device identifier, returning null when no matching record exists.

    public Task<PumpState?> FindByDeviceIdAsync(string deviceId)

#### Parameters

`deviceId` string

  The unique identifier of the device whose pump state should be looked up.

#### Returns

Task<PumpState>

  A PumpState instance if a matching record is found; otherwise, null.

### GetAllAsync()

Asynchronously retrieves all PumpState records from the data store.

    public Task<IEnumerable<PumpState>> GetAllAsync()

#### Returns

Task<IEnumerable<PumpState>>

  A task that represents the asynchronous operation, containing an IEnumerable<T> of all PumpState records; an empty collection is returned if no records exist.

### GetCollectionName()

Retrieves the collection name for pump states, returning the configured value from API settings or the default name "pump_states" when the setting is not provided.

    public override string GetCollectionName()

#### Returns

string

  The configured pump states collection name, or the default value "pump_states" if the setting is null.

### UpsertAsync(PumpState)

Inserts the specified PumpState or updates the existing one identified by its `DeviceId`. If a matching record is found, its identifier is reused; otherwise a new identifier is generated when the provided one is empty.

    public Task UpsertAsync(PumpState state)

#### Parameters

`state` PumpState

  The pump state to persist. Its `Id` is preserved or assigned based on whether a record with the same `DeviceId` already exists.

#### Returns

Task