using System.Threading;
using System.Threading.Tasks;
using Knot.Modules.Stories.Domain;
using Microsoft.EntityFrameworkCore;

namespace Knot.Modules.Stories.Infrastructure.Database;

public class StoriesDbContext : DbContext
{
    public StoriesDbContext(DbContextOptions<StoriesDbContext> options) : base(options)
    {
    }

    public DbSet<StoryViewer> StoryViewers => Set<StoryViewer>();

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.HasDefaultSchema("stories");

        modelBuilder.Entity<StoryViewer>(builder =>
        {
            builder.ToTable("StoryViewers");
            builder.HasKey(s => s.Id);
            builder.HasIndex(s => new { s.StoryId, s.UserId }).IsUnique();
        });
    }
}
