#nullable enable
using Baya.Application.Models.Common;

namespace Baya.Application.Models.Reviews;

/// <summary>The minimal booking facts a review submission needs — resolved from the <c>bookings</c> row to
/// enforce ownership, the completed/closed eligibility gate, and the nurse the aggregate belongs to.</summary>
public record ReviewableBooking(long BookingId, long CustomerProfileId, long NurseProfileId, string Status);

/// <summary>What <c>SubmitReviewCommand</c> returns — the new review id and its (always
/// <c>pending_moderation</c>) status, plus whether a low-rating support alert was raised.</summary>
public record SubmitReviewResult(long Id, string ModerationStatus, bool LowRatingAlertRaised);

/// <summary>What <c>ModerateReviewCommand</c> returns — the new status and the recomputed nurse aggregate
/// (so a caller/test can see the from-source recompute immediately). Rating is a decimal average.</summary>
public record ModerateReviewResult(long Id, string ModerationStatus, decimal AverageRating, int TotalReviews);

/// <summary>The result of attaching/replacing a review's tags — the review id and its resulting tag codes.</summary>
public record ReviewTagsResult(long ReviewId, IReadOnlyList<string> TagCodes);

/// <summary>A public, published review line item — never carries moderation internals.</summary>
public record ReviewListItemDto(
    long Id,
    int Rating,
    string? Body,
    IReadOnlyList<string> TagCodes,
    DateTimeOffset CreatedAt);

/// <summary>The public nurse rating aggregate — derived from <b>published</b> reviews only.</summary>
public record NurseReviewAggregateDto(decimal AverageRating, int PublishedCount);

/// <summary>The public reviews payload for a nurse — the aggregate plus a page of published reviews.</summary>
public record NurseReviewsResult(NurseReviewAggregateDto Aggregate, PagedResult<ReviewListItemDto> Reviews);

/// <summary>An admin moderation-queue row — the full review plus any linked low-rating alert id (internal use
/// only; support alerts never appear on a user-facing route).</summary>
public record ModerationQueueItemDto(
    long Id,
    long BookingId,
    long NurseProfileId,
    long CustomerProfileId,
    int Rating,
    string? Body,
    string ModerationStatus,
    string? ModerationReason,
    long? LowRatingAlertId,
    IReadOnlyList<string> TagCodes,
    DateTimeOffset CreatedAt);

/// <summary>One tag's rollup for a nurse — the count of published reviews carrying it and that as a percentage
/// of the nurse's published reviews.</summary>
public record TagAggregateDto(string Code, string LabelFa, string LabelEn, int Count, decimal Percentage);

/// <summary>The per-nurse tag rollup — the published-review base and each tag's share.</summary>
public record NurseTagAggregatesResult(int PublishedReviewCount, IReadOnlyList<TagAggregateDto> Tags);
