
package de.maci.photography.eyebeam.library.metadata;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.time.Instant;
import java.util.Optional;

/**
 * @author Daniel Götten <daniel.goetten@googlemail.com>
 * @since 10.10.15
 */
public class Metadata {

    public static final class ImageSize {

        private final int width;
        private final int height;

        public ImageSize(int width, int height) {
            this.width = width;
            this.height = height;
        }

        public int width() {
            return width;
        }

        public int height() {
            return height;
        }

        @Override
        public String toString() {
            final StringBuffer sb = new StringBuffer("ImageSize{");
            sb.append("width=").append(width);
            sb.append(", height=").append(height);
            sb.append('}');
            return sb.toString();
        }
    }

    private final Long fileSize;
    private final ImageSize imageSize;
    private final ExifData exifData;

    private final Instant gatheredAt;

    public Metadata(@Nullable Long fileSize,
                    @Nullable ImageSize imageSize,
                    @Nullable ExifData exifData) {
        this.fileSize = fileSize;
        this.imageSize = imageSize;
        this.exifData = exifData;

        this.gatheredAt = Instant.now();
    }

    @Nonnull
    public Optional<Long> fileSize() {
        return Optional.ofNullable(fileSize);
    }

    @Nonnull
    public Optional<ImageSize> imageSize() {
        return Optional.ofNullable(imageSize);
    }

    @Nonnull
    public Optional<ExifData> exifData() {
        return Optional.ofNullable(exifData);
    }

    @Nonnull
    public Instant extractedAt() {
        return gatheredAt;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("Metadata{");
        sb.append("exifData=").append(exifData);
        sb.append(", fileSize=").append(fileSize);
        sb.append(", imageSize=").append(imageSize);
        sb.append('}');
        return sb.toString();
    }

    public static Metadata empty() {
        return new Metadata(null, null, null);
    }
}
