package gc.mda.kcg.domain.osint;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public class OsintDto {

    private String id;
    private long timestamp;
    private String title;
    private String source;
    private String url;
    private String category;
    private String language;
    private String imageUrl;
    private Double lat;
    private Double lng;

    public static OsintDto from(OsintFeed f) {
        return OsintDto.builder()
                .id(f.getSource() + "-" + f.getId())
                .timestamp(f.getPublishedAt() != null
                        ? f.getPublishedAt().toEpochMilli()
                        : f.getCollectedAt().toEpochMilli())
                .title(f.getTitle())
                .source(f.getSource())
                .url(f.getSourceUrl())
                .category(f.getCategory())
                .language(f.getLanguage())
                .imageUrl(f.getImageUrl())
                .lat(f.getPosition() != null ? f.getPosition().getY() : null)
                .lng(f.getPosition() != null ? f.getPosition().getX() : null)
                .build();
    }
}
