using System.Text.Json;

namespace Tiku.Domain.Common;

public abstract class Entity
{
    public Guid Id { get; set; } = Guid.NewGuid();
}

public interface IHasTimestamps
{
    DateTimeOffset CreatedAt { get; set; }
    DateTimeOffset UpdatedAt { get; set; }
}

public interface ITenantOwned
{
    Guid TenantId { get; set; }
}

public abstract class AuditableEntity : Entity, IHasTimestamps
{
    public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
    public DateTimeOffset UpdatedAt { get; set; } = DateTimeOffset.UtcNow;
}

public abstract class TenantEntity : Entity, ITenantOwned
{
    public Guid TenantId { get; set; }
}

public abstract class AuditableTenantEntity : TenantEntity, IHasTimestamps
{
    public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
    public DateTimeOffset UpdatedAt { get; set; } = DateTimeOffset.UtcNow;
}

public static class JsonDefaults
{
    public static JsonElement Object()
    {
        using var document = JsonDocument.Parse("{}");
        return document.RootElement.Clone();
    }

    public static JsonElement Array()
    {
        using var document = JsonDocument.Parse("[]");
        return document.RootElement.Clone();
    }
}