package com.dne.ems.dto;

import com.dne.ems.model.Attachment;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class AttachmentDTO {
    private Long id;
    private String fileName;
    private String fileType;
    private String url;
    private LocalDateTime uploadedAt;

    public static AttachmentDTO fromEntity(Attachment attachment) {
        if (attachment == null) {
            return null;
        }
        String url = "/api/files/" + attachment.getStoredFileName();

        return new AttachmentDTO(
                attachment.getId(),
                attachment.getFileName(),
                attachment.getFileType(),
                url,
                attachment.getUploadDate()
        );
    }
} 