using System.ComponentModel.DataAnnotations;
using ERPCore.Domain.Enums;

namespace ERPCore.Dtos.ItemTypes;

/// <summary>
/// Item type resource (docs/11-BACKEND-PHASE1.md §2.7) — a dimension name such as Color
/// or Size. Carries no values and no item linkage: the chosen values are encoded into the
/// client-generated SKU rather than stored (docs/10 Part C.9).
/// <para>
/// <c>IsMeasurable</c> marks a dimension whose values are content measurements (500 ml, 1 L)
/// rather than plain labels; the builder captures a number + unit per value and writes it to
/// each generated item's content size.
/// </para>
/// </summary>
public sealed record ItemTypeDto(
    int ItemTypeId, string Name, bool IsMeasurable, EntityStatus Status, DateTime CreatedAt, DateTime? UpdatedAt);

// Request DTOs — narrow: server-controlled fields (status, ids, timestamps)
// are intentionally excluded to prevent over-posting (02-SECURITY B.6 / C.1). ----

public sealed class CreateItemTypeRequest
{
    [Required, StringLength(200)] public string Name { get; set; } = string.Empty;

    /// <summary>Omitted ⇒ false, i.e. plain-text values. See <see cref="ItemTypeDto"/>.</summary>
    public bool IsMeasurable { get; set; }
}

public sealed class UpdateItemTypeRequest
{
    [Required, StringLength(200)] public string Name { get; set; } = string.Empty;

    /// <summary>
    /// Nullable on purpose: a plain <c>bool</c> binds an absent property as <c>false</c>, so any
    /// client that PUT only a name — as the item-types screen used to — would silently clear the
    /// flag on every rename. Omitting this field <b>preserves</b> the stored value.
    /// </summary>
    public bool? IsMeasurable { get; set; }
}

public sealed class UpdateItemTypeStatusRequest
{
    [Required, EnumDataType(typeof(EntityStatus))] public EntityStatus Status { get; set; }
}
