package ai.decompile.job.model.dto;

import ai.decompile.job.model.entity.Job;
import ai.decompile.job.model.enums.JobStatus;
import ai.decompile.job.model.enums.JobType;
import jakarta.validation.constraints.NotNull;
import java.time.Instant;
import java.util.UUID;

public record JobResponse(
    @NotNull UUID id,
    @NotNull JobType type,
    @NotNull JobStatus status,
    @NotNull UUID projectId,
    @NotNull UUID binaryId,
    String binaryName,
    String projectName,
    String payload,
    String result,
    String errorMessage,
    int retryCount,
    @NotNull Instant createdAt,
    @NotNull Instant updatedAt) {
  public static JobResponse from(Job job) {
    return new JobResponse(
        job.getId(),
        job.getType(),
        job.getStatus(),
        job.getProjectId(),
        job.getBinaryId(),
        job.getBinary() != null ? job.getBinary().getFilename() : null,
        job.getProject() != null ? job.getProject().getName() : null,
        job.getPayload(),
        job.getResult(),
        job.getErrorMessage(),
        job.getRetryCount(),
        job.getCreatedAt(),
        job.getUpdatedAt());
  }
}
