import 'package:dartz/dartz.dart';
import '../../core/error/failures.dart';
import '../entities/price_info.dart';
import '../entities/market_overview.dart';
import '../entities/trading_account.dart';
import '../entities/asset_display.dart';
import '../entities/kline.dart';
import '../../data/models/trade_order_model.dart';

abstract class TradingRepository {
  /// 获取买入功能开关状态
  Future<Either<Failure, bool>> getBuyEnabled();

  /// 查询当前用户预种卖出限制状态（fail-open：异常时返回 false）
  Future<Either<Failure, bool>> getSellRestriction();

  /// 获取当前价格信息
  Future<Either<Failure, PriceInfo>> getCurrentPrice();

  /// 获取市场概览
  Future<Either<Failure, MarketOverview>> getMarketOverview();

  /// 获取交易账户信息
  Future<Either<Failure, TradingAccount>> getTradingAccount(String accountSequence);

  /// 创建订单
  Future<Either<Failure, Map<String, dynamic>>> createOrder({
    required String type,
    required String price,
    required String quantity,
  });

  /// 取消订单
  Future<Either<Failure, void>> cancelOrder(String orderNo);

  /// 获取用户订单列表
  Future<Either<Failure, OrdersPageModel>> getOrders({
    int page = 1,
    int pageSize = 50,
  });

  /// 获取用户成交记录（含手续费明细）
  Future<Either<Failure, TradesPageModel>> getTrades({
    int page = 1,
    int pageSize = 50,
  });

  /// 预估卖出收益
  Future<Either<Failure, Map<String, dynamic>>> estimateSell(String quantity);

  /// 划入积分股 (从挖矿账户到交易账户)
  Future<Either<Failure, Map<String, dynamic>>> transferIn(String amount);

  /// 划出积分股 (从交易账户到挖矿账户)
  Future<Either<Failure, Map<String, dynamic>>> transferOut(String amount);

  /// 获取划转历史记录
  Future<Either<Failure, List<dynamic>>> getTransferHistory({int page = 1, int pageSize = 50});

  /// 获取我的资产显示信息
  Future<Either<Failure, AssetDisplay>> getMyAsset({String? dailyAllocation});

  /// 获取指定账户资产显示信息
  Future<Either<Failure, AssetDisplay>> getAccountAsset(String accountSequence, {String? dailyAllocation});

  /// 获取K线数据
  /// [before] 获取此时间之前的K线数据（用于加载更多历史）
  Future<Either<Failure, List<Kline>>> getKlines({String period = '1h', int limit = 100, DateTime? before});
}
