package natumassas.natumassasapp.database;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.widget.Toast;

import natumassas.natumassasapp.R;

/**
 * @author Victor Carvalho
 * @since 16/09/2017
 */

public class DBConnection {

    public SQLiteDatabase connection;

    private DataOpenHelper dataOpenHelper;

    /**
     * Para debug.
     * @param activity
     * @param context
     */
    public void createConnection(Activity activity, Context context){
        try{
            dataOpenHelper = new DataOpenHelper(activity);

            connection = dataOpenHelper.getWritableDatabase();

            Toast.makeText(context, "Conex√£o com o banco bem sucedida", Toast.LENGTH_SHORT).show();
        }
        catch (SQLException e) {
            AlertDialog.Builder alert = new AlertDialog.Builder(activity);
            alert.setTitle(R.string.title_erro);
            alert.setMessage(e.getMessage());
            alert.setNeutralButton("Que Merda!", null);
            alert.show();
        }
    }

    public void createConnection(Activity activity){
        try{
            dataOpenHelper = new DataOpenHelper(activity);

            connection = dataOpenHelper.getWritableDatabase();
        }
        catch (SQLException e) {
            AlertDialog.Builder alert = new AlertDialog.Builder(activity);
            alert.setTitle(R.string.title_erro);
            alert.setMessage(e.getMessage());
            alert.setNeutralButton("OK", null);
            alert.show();
        }
    }
}