-- Table to store Vehicle Challan Check requests
CREATE TABLE IF NOT EXISTS `vehicle_challan` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `application_no` VARCHAR(100) NOT NULL,
  `username` VARCHAR(20) NOT NULL,
  `vehicle_number` VARCHAR(20) NOT NULL,
  `challan_count` INT UNSIGNED NOT NULL DEFAULT 0,
  `challan_data` LONGTEXT COMMENT 'raw JSON array of challans from API',
  `status` TINYINT(1) NOT NULL DEFAULT 0,
  `status_code` TEXT,
  `fee` DECIMAL(10,2) NOT NULL DEFAULT 0.00,
  `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_vehicle_number` (`vehicle_number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Add pricing entry (adjust price as needed)
INSERT INTO `pricing` (`service_name`, `price`) VALUES ('vehicle_challan', 15.00)
ON DUPLICATE KEY UPDATE price = price;
