/*
 * Copyright (c) 2020. Lemon Healthcare
 *
 *
 */

package com.lemonhc.mplus.barcode;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;

import com.m3.sdk.scannerlib.Barcode;
import com.m3.sdk.scannerlib.BarcodeListener;
import com.m3.sdk.scannerlib.BarcodeManager;

import lombok.NonNull;

public class BarcodeServiceImpl extends BarcodeService {

    private Context context;

    private Barcode mBarcode = null;
    private BarcodeListener mListener = null;
    private BarcodeManager mManager = null;
    private Barcode.Symbology mSymbology = null;

    public BarcodeServiceImpl(@NonNull Context context) {
        this.context = context;
    }

    @Override
    public void initScanBarcode() {
        mBarcode = new Barcode(this.context);
//        mBarcode.scanStart();
        mManager = new BarcodeManager(this.context);
        mSymbology = mBarcode.getSymbologyInstance();

        mListener = new BarcodeListener() {
            @Override
            public void onBarcode(String strBarcode) {
                Log.i("ScannerTest1","### result= " + strBarcode);
                BarcodeEventHandler.callEvent(BarcodeServiceImpl.class, strBarcode, true);
                Toast.makeText(context, "Barcode : " + strBarcode, Toast.LENGTH_SHORT).show();

            }

            @Override
            public void onBarcode(String barcode, String codeType) {
                Log.i("ScannerTest2","### data: " + barcode + " type: " + codeType);
            }

            @Override
            public void onGetSymbology(int nSymbol, int nVal) {
                Log.i("ScannerTest", "### onGetSymbology result= "+ nSymbol + ", "+ nVal);
            }
        };
        mManager.addListener(mListener);

    }

    @Override
    public void startScanBarcode() {

    }

    @Override
    public void stopScanBarcode() {

    }

}
