-- Table to store PAN to Aadhaar lookup requests
-- ⚠️ SECURITY NOTE: This table stores full Aadhaar numbers + DOB + name (sensitive PII).
-- Same considerations as other Aadhaar-handling tables in this project: restrict DB
-- access/backups appropriately, and consider masking the Aadhaar number in the UI
-- (e.g. showing only last 4 digits) if this data doesn't need to be fully visible
-- to end users after the lookup.

CREATE TABLE IF NOT EXISTS `pan_to_aadhaar` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `application_no` VARCHAR(100) NOT NULL,
  `username` VARCHAR(20) NOT NULL,
  `pan_number` VARCHAR(10) NOT NULL,
  `aadhaar_number` VARCHAR(15) DEFAULT NULL,
  `name` VARCHAR(150) DEFAULT NULL,
  `dob` VARCHAR(15) DEFAULT NULL,
  `gender` VARCHAR(5) DEFAULT NULL,
  `data_mode` VARCHAR(20) DEFAULT NULL,
  `source` VARCHAR(20) DEFAULT NULL,
  `billable` VARCHAR(1) DEFAULT 'Y' COMMENT 'Y = charged, N = free (cached hit)',
  `status` TINYINT(1) NOT NULL DEFAULT 0,
  `status_code` TEXT,
  `fee` DECIMAL(10,2) NOT NULL DEFAULT 0.00 COMMENT 'actual amount charged (0 if billable=N)',
  `old_balance` DECIMAL(12,2) NOT NULL DEFAULT 0.00,
  `new_balance` DECIMAL(12,2) NOT NULL DEFAULT 0.00,
  `message` VARCHAR(255) DEFAULT NULL,
  `date` DATETIME NOT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_username` (`username`),
  KEY `idx_application_no` (`application_no`),
  KEY `idx_pan_number` (`pan_number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Pricing: rate = 5 as specified (this is the MAX charge; actual charge waived when billable=N)
INSERT INTO `pricing` (`service_name`, `price`) VALUES ('pan_to_aadhaar', 5.00)
ON DUPLICATE KEY UPDATE price = 5.00;
