package org.loculus.backend.service.files

import org.jetbrains.exposed.sql.Table
import org.jetbrains.exposed.sql.kotlin.datetime.datetime
import java.util.UUID

typealias FileId = UUID
typealias MultipartUploadId = String
const val FILES_TABLE_NAME = "files"

/**
 * The files table is used to track files which are stored in S3.
 * This table is only used if the 'files' feature is actually enabled, which it isn't by default.
 * Files in S3 can only be uploaded through presigned URLs which are generated by the backend.
 * Note that the table tracks requested file IDs, not actual files in S3.
 */
object FilesTable : Table(FILES_TABLE_NAME) {

    val idColumn = uuid("id")

    /**
     * When the file upload was requested, i.e. the row in the table was created.
     * This is not the time when the file was actually uploaded to S3.
     */
    val uploadRequestedAtColumn = datetime("upload_requested_at")

    /**
     * The user requesting the file upload.
     */
    val uploaderColumn = text("uploader")

    /**
     * The group which owns the file.
     */
    val groupIdColumn = integer("group_id")

    /**
     * File size in bytes. Can be null.
     * If null, the file hasn't been uploaded yet, or file size hasn't been checked yet.
     */
    val sizeColumn = long("size").nullable()

    val multipartCompleted = bool("multipart_completed")

    val multipartUploadId = text("multipart_upload_id").nullable()

    val markedForDeletionAtColumn = datetime("marked_for_deletion_at").nullable()
}
