-- Table to store PAN to GST Search requests
CREATE TABLE IF NOT EXISTS `pan_to_gst_search` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `application_no` VARCHAR(100) NOT NULL,
  `username` VARCHAR(20) NOT NULL,
  `pan` VARCHAR(10) NOT NULL,
  `gst_count` INT UNSIGNED NOT NULL DEFAULT 0,
  `items_data` LONGTEXT COMMENT 'raw JSON array of GST records (gstin, auth_status, state) from API',
  `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` (`pan`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Pricing: rate = 2 (this is the MAX charge; actual charge waived when billable=N)
INSERT INTO `pricing` (`service_name`, `price`) VALUES ('pan_to_gst_search', 2.00)
ON DUPLICATE KEY UPDATE price = 2.00;
