-- create database (if not exists)
CREATE DATABASE IF NOT EXISTS school_admissions CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE school_admissions;

-- applications table
CREATE TABLE IF NOT EXISTS applications (
  id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  submitted_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,

  -- student / basic
  class_sought VARCHAR(100),
  reg_no VARCHAR(100),
  child_name VARCHAR(255) NOT NULL,
  gender VARCHAR(30),
  nationality VARCHAR(100),
  dob DATE,
  aadhar_child VARCHAR(20),
  res_address TEXT,
  last_school VARCHAR(255),
  email VARCHAR(255),

  -- father
  father_name VARCHAR(255),
  father_aadhar VARCHAR(20),
  father_phone VARCHAR(20),
  father_edu VARCHAR(255),
  father_occ VARCHAR(255),
  father_desig VARCHAR(255),
  father_org VARCHAR(255),
  father_org_addr TEXT,

  -- mother
  mother_name VARCHAR(255),
  mother_aadhar VARCHAR(20),
  mother_phone VARCHAR(20),
  mother_edu VARCHAR(255),
  mother_occ VARCHAR(255),
  mother_desig VARCHAR(255),
  mother_org VARCHAR(255),
  mother_org_addr TEXT,

  single_parent VARCHAR(50),

  -- sibling, medical, transport, category
  sibling_name VARCHAR(255),
  sibling_class VARCHAR(100),
  medical_need VARCHAR(10),
  medical_details TEXT,
  transfer_info VARCHAR(255),
  transport_req VARCHAR(10),
  category VARCHAR(50),

  declaration TINYINT(1) DEFAULT 0,

  -- uploaded file paths (relative to project root)
  photo_child_path VARCHAR(500),
  photo_father_path VARCHAR(500),
  photo_mother_path VARCHAR(500),
  sign_mother_path VARCHAR(500),
  sign_father_path VARCHAR(500),

  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  INDEX(idx_email) (email),
  INDEX(idx_father_phone) (father_phone),
  INDEX(idx_mother_phone) (mother_phone)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
