using ZB.MOM.WW.ScadaBridge.Commons.Entities.Instances;
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Sites;
namespace ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;
///
/// Repository interface for site and data connection management.
///
public interface ISiteRepository
{
// Sites
/// Retrieves a site by its ID.
/// The site primary key.
/// Cancellation token.
/// A task that resolves to the matching , or null if not found.
Task GetSiteByIdAsync(int id, CancellationToken cancellationToken = default);
/// Retrieves a site by its identifier.
/// The unique site identifier string.
/// Cancellation token.
/// A task that resolves to the matching , or null if not found.
Task GetSiteByIdentifierAsync(string siteIdentifier, CancellationToken cancellationToken = default);
/// Retrieves all sites.
/// Cancellation token.
/// A task that resolves to a read-only list of all entities.
Task> GetAllSitesAsync(CancellationToken cancellationToken = default);
/// Adds a new site.
/// The site entity to add.
/// Cancellation token.
/// A task that represents the asynchronous operation.
Task AddSiteAsync(Site site, CancellationToken cancellationToken = default);
/// Updates an existing site.
/// The site entity with updated values.
/// Cancellation token.
/// A task that represents the asynchronous operation.
Task UpdateSiteAsync(Site site, CancellationToken cancellationToken = default);
/// Deletes a site.
/// The site primary key.
/// Cancellation token.
/// A task that represents the asynchronous operation.
Task DeleteSiteAsync(int id, CancellationToken cancellationToken = default);
// Data Connections
/// Retrieves a data connection by its ID.
/// The data connection primary key.
/// Cancellation token.
/// A task that resolves to the matching , or null if not found.
Task GetDataConnectionByIdAsync(int id, CancellationToken cancellationToken = default);
/// Retrieves all data connections.
/// Cancellation token.
/// A task that resolves to a read-only list of all entities.
Task> GetAllDataConnectionsAsync(CancellationToken cancellationToken = default);
/// Retrieves all data connections for a site.
/// The site primary key to filter by.
/// Cancellation token.
/// A task that resolves to a read-only list of entities for the given site.
Task> GetDataConnectionsBySiteIdAsync(int siteId, CancellationToken cancellationToken = default);
/// Adds a new data connection.
/// The data connection entity to add.
/// Cancellation token.
/// A task that represents the asynchronous operation.
Task AddDataConnectionAsync(DataConnection connection, CancellationToken cancellationToken = default);
/// Updates an existing data connection.
/// The data connection entity with updated values.
/// Cancellation token.
/// A task that represents the asynchronous operation.
Task UpdateDataConnectionAsync(DataConnection connection, CancellationToken cancellationToken = default);
/// Deletes a data connection.
/// The data connection primary key.
/// Cancellation token.
/// A task that represents the asynchronous operation.
Task DeleteDataConnectionAsync(int id, CancellationToken cancellationToken = default);
// Instances (for deletion / move constraint checks)
/// Retrieves all instances deployed to a site.
/// The site primary key to filter by.
/// Cancellation token.
/// A task that resolves to a read-only list of entities for the given site.
Task> GetInstancesBySiteIdAsync(int siteId, CancellationToken cancellationToken = default);
///
/// Retrieves the distinct instances that have at least one
/// referencing the given data
/// connection. Used as the primary data-integrity guard for moving a
/// connection between sites: a bound connection cannot leave its site
/// without orphaning the (site-scoped) binding, so the move handler rejects
/// the move and names the returned instances as blockers.
///
/// The data connection primary key.
/// Cancellation token.
/// A task that resolves to the distinct referencing entities (empty when none).
Task> GetInstancesReferencingDataConnectionAsync(int dataConnectionId, CancellationToken cancellationToken = default);
///
/// Retrieves a site's instances with their
/// eagerly loaded. Purpose-built
/// for the move-data-connection guard, which must scan source-site instance
/// overrides for name-based connection references without paying the eager-load
/// cost on the hot-path .
///
/// The site primary key to filter by.
/// Cancellation token.
/// A task that resolves to the site's entities with overrides loaded (empty when none).
Task> GetInstancesWithNativeAlarmOverridesBySiteIdAsync(int siteId, CancellationToken cancellationToken = default);
/// Saves all pending changes to the database.
/// Cancellation token.
/// A task that resolves to the number of state entries written to the database.
Task SaveChangesAsync(CancellationToken cancellationToken = default);
}