using SIGCM2.Application.Common;
using SIGCM2.Domain.Entities;

namespace SIGCM2.Application.Abstractions.Persistence;

/// <summary>
/// Write-side repository for ProductType.
/// All reads needed by write handlers are included here.
/// Query-side (for listing, filtering) uses GetPagedAsync with ProductTypesQuery.
/// </summary>
public interface IProductTypeRepository
{
    /// <summary>Inserts a new ProductType and returns the DB-assigned Id.</summary>
    Task<int> AddAsync(ProductType productType, CancellationToken ct = default);

    /// <summary>Returns the ProductType with the given Id, or null if not found.</summary>
    Task<ProductType?> GetByIdAsync(int id, CancellationToken ct = default);

    /// <summary>Returns a paged result of ProductTypes matching the query.</summary>
    Task<PagedResult<ProductType>> GetPagedAsync(ProductTypesQuery query, CancellationToken ct = default);

    /// <summary>Persists all changes to an existing ProductType row.</summary>
    Task UpdateAsync(ProductType productType, CancellationToken ct = default);

    /// <summary>
    /// Returns true if an active ProductType with the given nombre exists.
    /// Pass excludeId to skip the self-comparison during rename (update scenario).
    /// Case-insensitive — delegates to DB collation (SQL_Latin1_General_CP1_CI_AI).
    /// </summary>
    Task<bool> ExistsByNombreAsync(string nombre, int? excludeId = null, CancellationToken ct = default);
}
