package com.wonderkiln.camerakit.base;


import com.google.android.gms.vision.Detector;
import com.google.android.gms.vision.text.TextBlock;
import com.wonderkiln.camerakit.CameraProperties;
import com.wonderkiln.camerakit.events.EventDispatcher;
import com.wonderkiln.camerakit.types.CaptureMethod;
import com.wonderkiln.camerakit.types.Facing;
import com.wonderkiln.camerakit.types.Flash;
import com.wonderkiln.camerakit.types.Focus;
import com.wonderkiln.camerakit.types.VideoQuality;
import com.wonderkiln.camerakit.utils.Size;

import java.io.File;

import androidx.annotation.Nullable;

public abstract class CameraImpl {

    protected final EventDispatcher mEventDispatcher;
    protected final PreviewImpl     mPreview;

    public  CameraImpl(EventDispatcher eventDispatcher, PreviewImpl preview) {
        mEventDispatcher = eventDispatcher;
        mPreview = preview;
    }

    public abstract void start();

    public abstract void stop();

    public abstract void setDisplayAndDeviceOrientation(int displayOrientation, int deviceOrientation);

    public abstract void setFacing(@Facing int facing);

    public abstract void setFlash(@Flash int flash);

    public abstract void setFocus(@Focus int focus);

    public abstract void setMethod(@CaptureMethod int method);

    public abstract void setTextDetector(Detector<TextBlock> detector);

    public abstract void setVideoQuality(@VideoQuality int videoQuality);

    public abstract void setVideoBitRate(int videoBitRate);

    public abstract void setLockVideoAspectRatio(boolean lockVideoAspectRatio);

    public abstract void setZoom(float zoomFactor);

    public abstract void modifyZoom(float modifier);

    public abstract void setDeviceOrientation(int orientation);

    public abstract void setFocusArea(float x, float y);

    public abstract void captureImage(ImageCapturedCallback callback);

    public interface ImageCapturedCallback {
        void imageCaptured(byte[] jpeg);
    }

    public void captureVideo(File videoFile, VideoCapturedCallback callback) {
        captureVideo(videoFile, 0, callback);
    }

    public abstract void captureVideo(File videoFile, int maxDuration, VideoCapturedCallback callback);

    public interface VideoCapturedCallback {
        void videoCaptured(File file);
    }

    public abstract void stopVideo();

    public abstract Size getCaptureResolution();

    public abstract Size getVideoResolution();

    public abstract Size getPreviewResolution();

    public abstract boolean isCameraOpened();

    public abstract boolean frontCameraOnly();

    @Nullable
    public abstract CameraProperties getCameraProperties();

}
