package ASimulatorSystem;

import java.sql.*;  

public class Conn{
    Connection c;
    Statement s;
    public Conn(){  
        try{  
            // Using H2 in-memory database for demo purposes
            Class.forName("org.h2.Driver");  
            c = DriverManager.getConnection("jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1", "sa", "");    
            s = c.createStatement(); 
            
            // Create tables for demo
            createTables();
            
        }catch(Exception e){ 
            System.out.println("Database connection error: " + e);
            // Create a mock statement for demo purposes
            s = null;
        }  
    }
    
    private void createTables() {
        try {
            // Create login table
            s.executeUpdate("CREATE TABLE IF NOT EXISTS login (cardno VARCHAR(20), pin VARCHAR(10))");
            
            // Create signup table  
            s.executeUpdate("CREATE TABLE IF NOT EXISTS signup (formno VARCHAR(20), name VARCHAR(50), fname VARCHAR(50), dob VARCHAR(20), gender VARCHAR(10), email VARCHAR(50), marital VARCHAR(20), address VARCHAR(100), city VARCHAR(30), pincode VARCHAR(10), state VARCHAR(30))");
            
            // Create signup2 table
            s.executeUpdate("CREATE TABLE IF NOT EXISTS signup2 (formno VARCHAR(20), religion VARCHAR(20), category VARCHAR(20), income VARCHAR(20), education VARCHAR(30), occupation VARCHAR(30), pan VARCHAR(20), aadhar VARCHAR(20), scitizen VARCHAR(10), eaccount VARCHAR(10))");
            
            // Create signup3 table
            s.executeUpdate("CREATE TABLE IF NOT EXISTS signup3 (formno VARCHAR(20), accountType VARCHAR(20), cardno VARCHAR(20), pin VARCHAR(10), facility VARCHAR(100))");
            
            // Create bank table for transactions
            s.executeUpdate("CREATE TABLE IF NOT EXISTS bank (pin VARCHAR(10), date VARCHAR(50), mode VARCHAR(20), amount VARCHAR(20))");
            
            // Insert demo data
            s.executeUpdate("INSERT INTO login VALUES ('1234567890123456', '1234')");
            s.executeUpdate("INSERT INTO signup VALUES ('1000', 'Demo User', 'Demo Father', '01/01/1990', 'Male', 'demo@email.com', 'Single', '123 Demo St', 'Demo City', '12345', 'Demo State')");
            
        } catch (Exception e) {
            System.out.println("Table creation error: " + e);
        }
    }
}  
