package inbox

import (
	"context"
	"database/sql"

	"ai-workflow-skill/internal/db"
)

func openInboxDB(ctx context.Context, dbPath string) (*sql.DB, error) {
	sqlDB, err := db.Open(ctx, dbPath)
	if err != nil {
		return nil, err
	}

	if err := db.ApplyMigrations(ctx, sqlDB); err != nil {
		_ = sqlDB.Close()
		return nil, err
	}

	return sqlDB, nil
}
