#nullable enable
using Baya.Application.Models.Common;
using Baya.Application.Models.PartnerCenters;
using Baya.Domain.Entities.PartnerCenters;

namespace Baya.Application.Contracts.Persistence;

/// <summary>
/// The <c>partner_centers</c> aggregate. Writes load tracked rows; reads project to DTOs and <b>never</b> return
/// the plaintext/full <c>settlement_iban</c> (masked to last 4). <see cref="ResolveCenterForBookingAsync"/> is
/// the single merchant-of-record resolver: invoices + settlement follow the center, not a hardcoded platform.
/// </summary>
public interface IPartnerCenterRepository
{
    Task AddAsync(PartnerCenter center, CancellationToken cancellationToken);

    /// <summary>Tracked center — for update/verify/activate. Null if absent.</summary>
    Task<PartnerCenter?> GetTrackedAsync(long centerId, CancellationToken cancellationToken);

    Task<bool> ExistsAsync(long centerId, CancellationToken cancellationToken);

    /// <summary>The admin detail view, with the settlement IBAN masked and the sponsored-nurse count. Null if absent.</summary>
    Task<PartnerCenterDetailDto?> GetDetailAsync(long centerId, CancellationToken cancellationToken);

    /// <summary>Admin paginated list (no IBAN), optional active filter, with sponsored-nurse counts.</summary>
    Task<PagedResult<PartnerCenterListItemDto>> ListAsync(bool? isActive, int page, int pageSize, CancellationToken cancellationToken);

    /// <summary>Resolves which center legally covers a booking (booking → nurse → <c>partner_center_id</c>),
    /// returning the issuer/settlement decision. Issuer is <c>partner_center</c> only when the sponsoring center
    /// is merchant-of-record; <c>platform</c> otherwise (incl. an unsponsored nurse). Null if the booking is absent.</summary>
    Task<CenterForBookingDto?> ResolveCenterForBookingAsync(long bookingId, CancellationToken cancellationToken);

    /// <summary>The center's dashboard admin <c>users.id</c> — the portal-scope check. Null if the center is absent.</summary>
    Task<int?> GetAdminUserIdAsync(long centerId, CancellationToken cancellationToken);

    /// <summary>The center dashboard read model (sponsored nurses + booking/invoice counts). Null if absent.</summary>
    Task<CenterDashboardDto?> GetDashboardAsync(long centerId, CancellationToken cancellationToken);
}
