package leigh.video.edltool;

import leigh.mecha.log.MechaLogger;
import leigh.mecha.log.MechaLoggerFactory;

import java.io.File;
import java.util.Objects;

public class SourceClip {
    private static final MechaLogger logger = MechaLoggerFactory.getLogger(SourceClip.class);
    private final File file;
    private final int length;

    public SourceClip(File file, int length) {
        this.file = file;
        this.length = length;
    }

    public File getFile() {
        return file;
    }

    public int getLength() {
        return length;
    }

    /**
     * Given a program of the given length, scale the corresponding timecode to this clip.
     */
    public int scale(int programLength) {
        float ratio = (length - 20) / programLength;
        logger.info("Calculated clip ratio: {}", ratio);
        return (int) ratio;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        SourceClip that = (SourceClip) o;
        return length == that.length && Objects.equals(file, that.file);
    }

    @Override
    public int hashCode() {
        return Objects.hash(file, length);
    }
}
