package server.db.common;

import server.errors.ServerException;
import shared.models.*;

import java.sql.SQLException;
import java.util.List;

public abstract class Transaction {

    public static boolean logic(Transaction transaction, Database database) {
        try {
            return transaction.logic();
        } catch (SQLException e) {
            System.out.println("TODO: SWAP WITH LOGGER LOGIC SAVE FUNCTION ERROR");
        } catch (ServerException e) {
            System.out.println("TODO: SWAP WITH LOGGER LOGIC COMMIT FUNCTION ERROR");
        } finally {
            try {
                database.closeConnection();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        return false;
    }

    public static Object object(Transaction transaction, Database database) {
        try {
            return transaction.object();
        } catch (SQLException e) {
            System.out.println("TODO: SWAP WITH LOGGER object SAVE FUNCTION ERROR");
        } catch (ServerException e) {
            System.out.println("TODO: SWAP WITH LOGGER object COMMIT FUNCTION ERROR");
        } finally {
            try {
                database.closeConnection();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        return null;
    }

    public static List<Object> array(Transaction transaction, Database database) {
        try {
            return transaction.array();
        } catch (SQLException e) {
            System.out.println("TODO: SWAP WITH LOGGER array SAVE FUNCTION ERROR");
        } catch (ServerException e) {
            System.out.println("TODO: SWAP WITH LOGGER array COMMIT FUNCTION ERROR");
        } finally {
            try {
                database.closeConnection();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        return null;
    }

    public Object object() throws SQLException, ServerException {
        return null;
    }

    public boolean logic() throws SQLException, ServerException {
        return false;
    }

    public List<Object> array() throws SQLException, ServerException {
        return null;
    }

    public void transaction() throws SQLException, ServerException {
    }

}
