package com.datarecovery.master.dialog;

import android.content.Context;

import androidx.annotation.NonNull;

import com.datarecovery.master.R;
import com.datarecovery.master.data.consts.EventId;
import com.datarecovery.master.databinding.DialogUnlockFunctionBinding;
import com.datarecovery.master.handler.EventHelper;
import com.datarecovery.master.module.homepage.FunctionBean;
import com.datarecovery.master.utils.Maps;

@BaseDialog.FullScreen
public class UnlockFunctionDialog extends BaseDialog<DialogUnlockFunctionBinding> {

    private final int eventId;
    private ActionHandler actionHandler;

    public UnlockFunctionDialog(@NonNull Context context, int function) {
        super(context, R.style.Theme_Common_Dialog);
        setCancelable(false);
        this.eventId = getEventIdByFunction(function);
        binding.setOnUnlockClickListener(v -> {
            if (actionHandler != null) {
                actionHandler.onUnlock();
            }
            dismiss();
            EventHelper.report(EventId.EVENT_3000301, Maps.asMap("id", eventId));
        });
        binding.setOnCloseClickListener(v -> {
            dismiss();
            EventHelper.report(EventId.EVENT_3000302, Maps.asMap("id", eventId));
        });
    }

    private int getEventIdByFunction(int function) {
        switch (function) {
            case FunctionBean.IMG_RECOVERY:
                return 101;
            case FunctionBean.FILE_RECOVERY:
                return 102;
            case FunctionBean.VIDEO_RECOVERY:
                return 103;
            case FunctionBean.AUDIO_RECOVERY:
                return 104;
            case FunctionBean.IMG_CLEARING:
                return 105;
        }
        return 0;
    }

    public UnlockFunctionDialog setActionHandler(ActionHandler actionHandler) {
        this.actionHandler = actionHandler;
        return this;
    }

    @Override
    protected void onShow() {
        super.onShow();
        EventHelper.report(EventId.EVENT_3000300, Maps.asMap("id", eventId));
    }

    public interface ActionHandler {
        void onUnlock();
    }
}
