using Baya.Domain.Common;
using Baya.Domain.Entities.Identity;

namespace Baya.Domain.Entities.Catalog;

/// <summary>
/// The <b>atomic bookable unit</b> of the marketplace: a nurse offering a category with a chosen option
/// combination at their own price and price unit. Search (b7), booking (b8), and every money calculation
/// operate on a <i>variant</i> — never on "a nurse". A nurse with no active variant is not bookable.
/// <para>
/// <see cref="Price"/> is <b>IRR Rials as an integer</b> — no float, ever. The engagement total is
/// <see cref="Price"/> combined with <see cref="PriceUnit"/> and <see cref="SessionCount"/>; a downstream
/// consumer (booking) derives it from all three, never from price alone.
/// </para>
/// <para>
/// <see cref="OptionSetHash"/> is a deterministic hash of the sorted answered
/// <c>(option_group_id, option_value_id)</c> pairs. It backs the filtered
/// <c>UNIQUE(nurse_id, service_category_id, option_set_hash) WHERE deleted_at IS NULL</c> that makes the
/// duplicate-listing guard race-safe (a multi-row option-set can't be a plain composite unique index).
/// </para>
/// </summary>
public class NurseServiceVariant : BaseEntity<long>
{
    public long NurseId { get; set; }
    public NurseProfile Nurse { get; set; }

    public long ServiceCategoryId { get; set; }
    public ServiceCategory ServiceCategory { get; set; }

    /// <summary>IRR Rials, integer — never a float/decimal-with-fraction. There is no Toman in the DB.</summary>
    public long Price { get; set; }

    /// <summary>Closed code set — see <see cref="PriceUnits"/>. The only code enum in the catalog area.</summary>
    public string PriceUnit { get; set; }

    /// <summary>Number of sessions/units the engagement spans; relevant for <c>per_session</c> and packages.</summary>
    public int? SessionCount { get; set; }

    /// <summary>Auto-generated from the option labels at create time, but nurse-editable.</summary>
    public string DisplayName { get; set; }

    /// <summary>Deterministic hash of the sorted answered option-set — the duplicate-listing DB backstop key.</summary>
    public string OptionSetHash { get; set; }

    public bool IsActive { get; set; }

    public DateTimeOffset? DeletedAt { get; set; }

    public ICollection<NurseServiceVariantOption> Options { get; set; }
}
