using Managing.Application.Abstractions;
using Managing.Application.Abstractions.Services;
using Managing.Domain.Bots;
using Managing.Domain.MoneyManagements;
using Managing.Domain.Workflows;
using Microsoft.Extensions.Logging;
using static Managing.Common.Enums;

namespace Managing.Application.Bots.Base
{
    public class BotFactory : IBotFactory
    {
        private readonly IExchangeService _exchangeService;
        private readonly IMessengerService _messengerService;
        private readonly IAccountService _accountService;
        private readonly ILogger<TradingBot> _tradingBotLogger;
        private readonly ITradingService _tradingService;
        private readonly IBotService _botService;

        public BotFactory(
            IExchangeService exchangeService,
            ILogger<TradingBot> tradingBotLogger,
            IMessengerService messengerService,
            IAccountService accountService,
            ITradingService tradingService,
            IBotService botService)
        {
            _tradingBotLogger = tradingBotLogger;
            _exchangeService = exchangeService;
            _messengerService = messengerService;
            _accountService = accountService;
            _tradingService = tradingService;
            _botService = botService;
        }

        IBot IBotFactory.CreateSimpleBot(string botName, Workflow workflow)
        {
            return new SimpleBot(botName, _tradingBotLogger, workflow, _botService);
        }

        ITradingBot IBotFactory.CreateScalpingBot(string accountName, MoneyManagement moneyManagement, string name, Ticker ticker, string scenario, Timeframe interval, bool isForWatchingOnly, decimal initialTradingBalance)
        {
            return new ScalpingBot(
                accountName,
                moneyManagement,
                name,
                scenario,
                _exchangeService,
                ticker,
                _tradingService,
                _tradingBotLogger,
                interval,
                _accountService,
                _messengerService,
                _botService,
                initialTradingBalance,
                isForWatchingOnly: isForWatchingOnly);
        }

        ITradingBot IBotFactory.CreateBacktestScalpingBot(string accountName, MoneyManagement moneyManagement, Ticker ticker, string scenario, Timeframe interval, bool isForWatchingOnly, decimal initialTradingBalance)
        {
            return new ScalpingBot(
                accountName,
                moneyManagement,
                "BacktestBot",
                scenario,
                _exchangeService,
                ticker,
                _tradingService,
                _tradingBotLogger,
                interval,
                _accountService,
                _messengerService,
                _botService,
                initialTradingBalance,
                isForBacktest: true,
                isForWatchingOnly: isForWatchingOnly);
        }

        public ITradingBot CreateFlippingBot(string accountName, MoneyManagement moneyManagement, string name, Ticker ticker, string scenario, Timeframe interval, bool isForWatchingOnly, decimal initialTradingBalance)
        {
            return new FlippingBot(
                accountName,
                moneyManagement,
                name,
                scenario,
                _exchangeService,
                ticker,
                _tradingService,
                _tradingBotLogger,
                interval,
                _accountService,
                _messengerService,
                _botService,
                initialTradingBalance,
                isForWatchingOnly: isForWatchingOnly);
        }

        public ITradingBot CreateBacktestFlippingBot(string accountName, MoneyManagement moneyManagement, Ticker ticker, string scenario, Timeframe interval, bool isForWatchingOnly, decimal initialTradingBalance)
        {
            return new FlippingBot(
                accountName,
                moneyManagement,
                "BacktestBot",
                scenario,
                _exchangeService,
                ticker,
                _tradingService,
                _tradingBotLogger,
                interval,
                _accountService,
                _messengerService,
                _botService,
                initialTradingBalance,
                isForBacktest: true,
                isForWatchingOnly: isForWatchingOnly);
        }
    }
}
