package dev.lions.unionflow.server.repository;

import dev.lions.unionflow.server.entity.BackupRecord;
import io.quarkus.hibernate.orm.panache.PanacheRepositoryBase;
import io.quarkus.panache.common.Sort;
import jakarta.enterprise.context.ApplicationScoped;

import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

@ApplicationScoped
public class BackupRecordRepository implements PanacheRepositoryBase<BackupRecord, UUID> {

    public List<BackupRecord> findAllOrderedByDate() {
        return findAll(Sort.by("dateCreation", Sort.Direction.Descending)).list();
    }

    public void updateStatus(UUID id, String status, Long sizeBytes, LocalDateTime completedAt, String errorMessage) {
        update("status = ?1, sizeBytes = ?2, completedAt = ?3, errorMessage = ?4 WHERE id = ?5",
                status, sizeBytes, completedAt, errorMessage, id);
    }
}
