using Predictalytics.Domain.Entities;
using Predictalytics.Domain.Interfaces;
using Microsoft.EntityFrameworkCore;

namespace Predictalytics.Infrastructure.Data.Repositories;

public class InsiderWatchRepository : IInsiderWatchRepository
{
    private readonly AppDbContext _db;
    public InsiderWatchRepository(AppDbContext db) => _db = db;

    public async Task<IReadOnlyList<InsiderWatch>> GetAllAsync(CancellationToken ct = default)
        => await _db.InsiderWatches.ToListAsync(ct);

    public async Task<InsiderWatch?> GetByTraderIdAsync(int traderId, CancellationToken ct = default)
        => await _db.InsiderWatches.FirstOrDefaultAsync(i => i.TraderId == traderId, ct);

    public async Task AddAsync(InsiderWatch entry, CancellationToken ct = default)
    { _db.InsiderWatches.Add(entry); await _db.SaveChangesAsync(ct); }

    public async Task UpdateAsync(InsiderWatch entry, CancellationToken ct = default)
    { _db.InsiderWatches.Update(entry); await _db.SaveChangesAsync(ct); }
}
