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

namespace ERPCore.Dtos.Categories;

// Category (docs/11-BACKEND-PHASE1.md §2.3) ------------------------------------
// The hierarchy is exactly two levels: Category → SubCategory. The former
// self-nesting tree (parentId / ?tree=true / CategoryTreeDto) was removed in
// migration #2 — see docs/10 Part C.1.

/// <summary>Category resource — the top level.</summary>
public sealed record CategoryDto(
    int CategoryId, string Name, EntityStatus Status, DateTime CreatedAt, DateTime? UpdatedAt);

/// <summary>Subcategory resource — the single optional level below a category.</summary>
public sealed record SubCategoryDto(
    int SubCategoryId, int CategoryId, string Name, 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 CreateCategoryRequest
{
    [Required, StringLength(200)] public string Name { get; set; } = string.Empty;
}

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

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

/// <summary>Body for <c>POST /categories/{categoryId}/subcategories</c>; the parent comes from the route.</summary>
public sealed class CreateSubCategoryRequest
{
    [Required, StringLength(200)] public string Name { get; set; } = string.Empty;
}

/// <summary>
/// Body for <c>PUT /subcategories/{id}</c>. Name only — a subcategory cannot be reparented,
/// since moving one would silently invalidate the category of every item referencing it.
/// </summary>
public sealed class UpdateSubCategoryRequest
{
    [Required, StringLength(200)] public string Name { get; set; } = string.Empty;
}

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