using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using PolyTrader.Modules.CopyTrading.Persistence;
using PolyTraderSharp.Models;

namespace PolyTrader.Tests.Fakes
{
    /// <summary>In-Memory-Stub für <see cref="ICopyTradeLogRepository"/> (Service-Tests).</summary>
    public sealed class FakeCopyTradeLogRepository : ICopyTradeLogRepository
    {
        public List<ClosedTrade> Inserted { get; } = new();

        public void EnsureIndexes() { }
        public bool Exists(int accountId, string tokenId) => Inserted.Any(t => t.AccountId == accountId && t.TokenId == tokenId);
        public void Insert(ClosedTrade trade) => Inserted.Add(trade);
        public int GetMaxTradeId() => Inserted.Count == 0 ? 0 : Inserted.Max(t => t.TradeId);
        public List<ClosedTrade> Find(Expression<Func<ClosedTrade, bool>> predicate) => Inserted.Where(predicate.Compile()).ToList();
    }
}
