const { User, Asset } = require('../models');
const { NotFoundError, BadRequestError } = require('../utils/errors');
const config = require('../config');

class PublicService {


  async getJob() {
    const Crypto = await Asset.findAll({
        where: {type: 'crypto'}
    })
    const tradingPair = {BTC: ['USDT', 'ETH', 'LTC'], ETH: ['USDT', 'BTC', 'LTC']};
    const tradingPairs = [];
    for(const [base, quoteList] of Object.entries(tradingPair)) {
       const baseAsset = Crypto.find(asset => asset.symbol === base);
       if(!baseAsset) {
        continue;
       }
        for(const quote of quoteList) {
          const quoteAsset = Crypto.find(asset => asset.symbol === quote);
          if(!quoteAsset) {
            continue;
          }
          const name  = `${base}_${quote}`;
          const symbol = `${base}/${quote}`;
          tradingPairs.push({
            name,
            symbol,
            baseAsset: baseAsset.id,
            quoteAsset:   quoteAsset.id,
            market: 'spot',
            minQuantity: 0.0001,
            maxQuantity: 1000,
            quantityStep: 0.0001,
            tickSize: 0.00000001,
          })
        }
    }
    TradingPair.bulkCreate(tradingPairs, { ignoreDuplicates: true });
    return { status: 'pending', crypto: Crypto };
  }

}

module.exports = new PublicService();
