import { AppDataSource } from "../db/data-source";
import { TradingPair } from "../db/entities/trading-pair.entity";

const repo = AppDataSource.getRepository(TradingPair);

export async function getAllPairs() {
    const pairs = await repo.find({});
    return pairs;
}

export async function getPairLastBackfillTime(symbol: string) {
    const pair = await repo.findOneBy({
        symbol
    });
    return pair?.last_backfill_time;
}

export async function updatePairLastBackfillTime(symbol: string, time: Date) {
    const pair = await repo.findOneBy({
        symbol
    });
    if (pair === null) {
        return;
    }
    pair.last_backfill_time = time;
    return pair.save();
}
