using ColaFlow.Modules.Mcp.Domain.Entities;
using ColaFlow.Modules.Mcp.Infrastructure.Persistence.Configurations;
using Microsoft.EntityFrameworkCore;

namespace ColaFlow.Modules.Mcp.Infrastructure.Persistence;

/// <summary>
/// DbContext for MCP module
/// </summary>
public class McpDbContext(DbContextOptions<McpDbContext> options) : DbContext(options)
{
    public DbSet<McpApiKey> ApiKeys => Set<McpApiKey>();
    public DbSet<PendingChange> PendingChanges => Set<PendingChange>();
    public DbSet<TaskLock> TaskLocks => Set<TaskLock>();

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

        // Apply configurations
        modelBuilder.ApplyConfiguration(new McpApiKeyConfiguration());
        modelBuilder.ApplyConfiguration(new PendingChangeConfiguration());
        modelBuilder.ApplyConfiguration(new TaskLockConfiguration());

        // Set default schema
        modelBuilder.HasDefaultSchema("mcp");
    }
}
