using ZB.MOM.WW.ScadaBridge.Commons.Entities.Security;

namespace ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;

public interface ISecurityRepository
{
    // LdapGroupMapping
    /// <summary>
    /// Gets an LDAP group mapping by ID.
    /// </summary>
    /// <param name="id">The mapping ID.</param>
    /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param>
    /// <returns>The LDAP group mapping, or null if not found.</returns>
    Task<LdapGroupMapping?> GetMappingByIdAsync(int id, CancellationToken cancellationToken = default);
    /// <summary>
    /// Gets all LDAP group mappings.
    /// </summary>
    /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param>
    /// <returns>A read-only list of all LDAP group mappings.</returns>
    Task<IReadOnlyList<LdapGroupMapping>> GetAllMappingsAsync(CancellationToken cancellationToken = default);
    /// <summary>
    /// Gets all LDAP group mappings for a specific role.
    /// </summary>
    /// <param name="role">The role name.</param>
    /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param>
    /// <returns>A read-only list of LDAP group mappings for the role.</returns>
    Task<IReadOnlyList<LdapGroupMapping>> GetMappingsByRoleAsync(string role, CancellationToken cancellationToken = default);
    /// <summary>
    /// Adds a new LDAP group mapping.
    /// </summary>
    /// <param name="mapping">The LDAP group mapping to add.</param>
    /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param>
    /// <returns>A task representing the asynchronous operation.</returns>
    Task AddMappingAsync(LdapGroupMapping mapping, CancellationToken cancellationToken = default);
    /// <summary>
    /// Updates an existing LDAP group mapping.
    /// </summary>
    /// <param name="mapping">The LDAP group mapping to update.</param>
    /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param>
    /// <returns>A task representing the asynchronous operation.</returns>
    Task UpdateMappingAsync(LdapGroupMapping mapping, CancellationToken cancellationToken = default);
    /// <summary>
    /// Deletes an LDAP group mapping by ID.
    /// </summary>
    /// <param name="id">The mapping ID to delete.</param>
    /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param>
    /// <returns>A task representing the asynchronous operation.</returns>
    Task DeleteMappingAsync(int id, CancellationToken cancellationToken = default);

    // SiteScopeRule
    /// <summary>
    /// Gets a site scope rule by ID.
    /// </summary>
    /// <param name="id">The scope rule ID.</param>
    /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param>
    /// <returns>The site scope rule, or null if not found.</returns>
    Task<SiteScopeRule?> GetScopeRuleByIdAsync(int id, CancellationToken cancellationToken = default);
    /// <summary>
    /// Gets all site scope rules for an LDAP group mapping.
    /// </summary>
    /// <param name="ldapGroupMappingId">The LDAP group mapping ID.</param>
    /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param>
    /// <returns>A read-only list of scope rules for the mapping.</returns>
    Task<IReadOnlyList<SiteScopeRule>> GetScopeRulesForMappingAsync(int ldapGroupMappingId, CancellationToken cancellationToken = default);
    /// <summary>
    /// Adds a new site scope rule.
    /// </summary>
    /// <param name="rule">The site scope rule to add.</param>
    /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param>
    /// <returns>A task representing the asynchronous operation.</returns>
    Task AddScopeRuleAsync(SiteScopeRule rule, CancellationToken cancellationToken = default);
    /// <summary>
    /// Updates an existing site scope rule.
    /// </summary>
    /// <param name="rule">The site scope rule to update.</param>
    /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param>
    /// <returns>A task representing the asynchronous operation.</returns>
    Task UpdateScopeRuleAsync(SiteScopeRule rule, CancellationToken cancellationToken = default);
    /// <summary>
    /// Deletes a site scope rule by ID.
    /// </summary>
    /// <param name="id">The scope rule ID to delete.</param>
    /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param>
    /// <returns>A task representing the asynchronous operation.</returns>
    Task DeleteScopeRuleAsync(int id, CancellationToken cancellationToken = default);

    /// <summary>
    /// Saves all pending changes to the database.
    /// </summary>
    /// <param name="cancellationToken">A cancellation token that can be used to cancel the operation.</param>
    /// <returns>A task representing the number of entities saved.</returns>
    Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
}
