using Microsoft.EntityFrameworkCore;

namespace Freman.Sample.Web.Data;

public sealed class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options)
{
    public DbSet<Note> Notes => Set<Note>();

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        modelBuilder.Entity<Note>(b =>
        {
            b.ToTable("notes");
            b.HasKey(x => x.Id);
            b.Property(x => x.Text).HasMaxLength(500).IsRequired();
            b.Property(x => x.CreatedUtc).IsRequired();
            b.HasIndex(x => x.CreatedUtc);
        });
    }
}