using System.ComponentModel.DataAnnotations.Schema;

namespace Domain.SeedWork;

public class Entity
{
    public Entity()
    {
        Id = Guid.CreateVersion7();

        SetInsertDateTime();
    }

    [DatabaseGenerated
    (DatabaseGeneratedOption.None)]
    public Guid Id { get; protected set; }

    public long InsertDateTime { get; protected set; }
    public long UpdateDateTime { get; protected set; }
    public long? DeleteDateTime { get; protected set; }

    public bool IsActive { get; protected set; }
    public bool IsDeleted { get; protected set; }


    public void SetInsertDateTime()
    {
        InsertDateTime =
            DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
    }

    public void SetUpdateDateTime()
    {
        UpdateDateTime =
            DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
    }

    public void SetDeleteDateTime()
    {
        DeleteDateTime =
            DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
    }

    public void Activate()
    {
        IsActive = true;
    }

    public void Deactivate()
    {
        IsActive = false;
    }

    public void Delete()
    {
        IsDeleted = true;
        SetDeleteDateTime();
    }
}