# Class HistoricalConfigChangesRepository

Namespace
  adas_core.Infrastructure.Repositories

Assembly
  adas-core.Infrastructure.dll

Repository implementation for managing HistoricalConfigChanges entities in MongoDB. Provides CRUD operations and specialized queries for tracking configuration changes over time.

    public class HistoricalConfigChangesRepository : MongoRepository<HistoricalConfigChanges>, IHistoricalConfigChangesRepository, IMongoRepository<HistoricalConfigChanges>

Inheritance
  object
  MongoRepository<HistoricalConfigChanges>
  HistoricalConfigChangesRepository

Implements
  IHistoricalConfigChangesRepository
  IMongoRepository<HistoricalConfigChanges>

Inherited Members
  MongoRepository<HistoricalConfigChanges>.Db
  MongoRepository<HistoricalConfigChanges>.Collection
  MongoRepository<HistoricalConfigChanges>.UpdateOneAsync(ObjectId, HistoricalConfigChanges)
  MongoRepository<HistoricalConfigChanges>.DeleteAsync(ObjectId)
  MongoRepository<HistoricalConfigChanges>.InsertInitialLoad()
  MongoRepository<HistoricalConfigChanges>.InsertManyAsync(List<HistoricalConfigChanges>)
  MongoRepository<HistoricalConfigChanges>.UpdateManyObjectIdAsync(string, ObjectId, ObjectId)
  MongoRepository<HistoricalConfigChanges>.DeleteAsync(string)
  MongoRepository<HistoricalConfigChanges>.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?)

## Constructors

### HistoricalConfigChangesRepository(IOptions<ApiSettings>, IMongoDatabase, ILogger<HistoricalConfigChangesRepository>)

Initializes a new instance of the HistoricalConfigChangesRepository.

    public HistoricalConfigChangesRepository(IOptions<ApiSettings> apiSettings, IMongoDatabase database, ILogger<HistoricalConfigChangesRepository> logger)

#### Parameters

`apiSettings` IOptions<ApiSettings>

  API settings containing collection names configuration.

`database` IMongoDatabase

  The MongoDB database instance.

`logger` ILogger<HistoricalConfigChangesRepository>

  Logger for repository operations.

#### Exceptions

ArgumentNullException

  Thrown when apiSettings is null.

## Methods

### CreateIndexes()

Creates the necessary indexes for the HistoricalConfigChanges collection. Creates compound indexes on (configType, time) and (username, time) for improved query performance.

    public override Task CreateIndexes()

#### Returns

Task

#### Exceptions

Exception

  Throws an exception if index creation fails; logs error details before throwing.

### Delete(ObjectId)

Deletes a historical configuration change record by its ID.

    public Task<HistoricalConfigChanges?> Delete(ObjectId id)

#### Parameters

`id` ObjectId

  The ObjectId of the record to delete.

#### Returns

Task<HistoricalConfigChanges>

  The deleted HistoricalConfigChanges if found; otherwise, null.

### FindAll()

Retrieves all historical configuration change records.

    public Task<ICollection<HistoricalConfigChanges>> FindAll()

#### Returns

Task<ICollection<HistoricalConfigChanges>>

  A collection of all HistoricalConfigChanges entities.

### FindAllIds()

Retrieves all IDs of historical configuration change records.

    public Task<List<ObjectId>> FindAllIds()

#### Returns

Task<List<ObjectId>>

  A list of all ObjectIds in the collection.

### FindById(ObjectId)

Retrieves a historical configuration change record by its ID.

    public Task<HistoricalConfigChanges?> FindById(ObjectId id)

#### Parameters

`id` ObjectId

  The ObjectId of the record to retrieve.

#### Returns

Task<HistoricalConfigChanges>

  The HistoricalConfigChanges if found; otherwise, null.

### FindLastHistoricalConfigChangesByType(ConfigTypes, int)

Retrieves the most recent historical configuration changes for a specific configuration type. Results are sorted by time in descending order.

    public Task<ICollection<HistoricalConfigChanges>> FindLastHistoricalConfigChangesByType(DisplayConfigEnums.ConfigTypes cfgType, int num = 10)

#### Parameters

`cfgType` DisplayConfigEnums.ConfigTypes

  The type of configuration to filter by.

`num` int

  The maximum number of records to retrieve. Default is 10.

#### Returns

Task<ICollection<HistoricalConfigChanges>>

  A collection of the most recent HistoricalConfigChanges for the specified type.

### FindLastHistoricalConfigChangesByUser(string, ConfigTypes?, int)

Retrieves the most recent historical configuration changes for a specific user. Optionally filters by configuration type. Results are sorted by time in descending order.

    public Task<ICollection<HistoricalConfigChanges>> FindLastHistoricalConfigChangesByUser(string user, DisplayConfigEnums.ConfigTypes? cfgType = null, int num = 10)

#### Parameters

`user` string

  The username to filter by.

`cfgType` DisplayConfigEnums.ConfigTypes?

  Optional configuration type to filter by. If null, all types are included.

`num` int

  The maximum number of records to retrieve. Default is 10.

#### Returns

Task<ICollection<HistoricalConfigChanges>>

  A collection of the most recent HistoricalConfigChanges for the specified user.

### GetCollectionName()

Gets the name of the collection for historical configuration changes.

    public override string GetCollectionName()

#### Returns

string

  The collection name from API settings, or default "historicalConfigChanges".

### InsertOneAsync(HistoricalConfigChanges)

Inserts a new historical configuration change record and returns the inserted document.

    public override Task<HistoricalConfigChanges?> InsertOneAsync(HistoricalConfigChanges historicalConfigChanges)

#### Parameters

`historicalConfigChanges` HistoricalConfigChanges

  The HistoricalConfigChanges entity to insert.

#### Returns

Task<HistoricalConfigChanges>

  The inserted HistoricalConfigChanges with generated ID, or null if insertion fails.

#### Exceptions

Exception

  Logs errors and returns null on failure.

### Update(HistoricalConfigChanges)

Updates an existing historical configuration change record.

    public Task<HistoricalConfigChanges?> Update(HistoricalConfigChanges historicalConfigChanges)

#### Parameters

`historicalConfigChanges` HistoricalConfigChanges

  The HistoricalConfigChanges with updated values.

#### Returns

Task<HistoricalConfigChanges>

  The updated HistoricalConfigChanges if successful; otherwise, null.