using Microsoft.EntityFrameworkCore;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using e_suite.Database.Audit.Attributes;
using eSuite.Core.Sequences;
using e_suite.Database.Core.Models;

namespace e_suite.Database.Core.Tables.Sequences;

[DisplayName("Sequence")]
[Table("Sequences", Schema = "Sequences")]
[Index(nameof(Name), IsUnique = true)]
[Index(nameof(Guid), IsUnique = true)]
public class Sequence : IGeneralId, ISoftDeletable
{
    [Key]
    public long Id { get; set; }

    [AuditName]
    [Required]
    public string Name { get; set; } = string.Empty;

    [Required]
    public Rollover Rollover { get; set; } = Rollover.Continuous;

    [Required]
    [MaxLength(255)]
    public string Pattern { get; set; } = string.Empty;

    [Required]
    [DefaultValue(1)]
    public long Seed { get; set; } = 1;

    [Required]
    [DefaultValue(1)]
    public long Increment { get; set; } = 1;

    [AuditSoftDelete(true)]
    [Required]
    [DefaultValue(false)]
    public bool Deleted { get; set; } = false;

    [Required]
    public Guid Guid { get; set; } = Guid.NewGuid();

    public DateTimeOffset? LastIssueDate { get; set; } = null!;

    public long? LastIssueValue { get; set; } = null!;

    [AuditLastUpdated]
    public DateTimeOffset LastUpdated { get; set; }
}