-- Add structured booking timing/billing fields for daily and hourly car rental.
-- Safe to run after backup. Existing daily bookings keep their current totals.

USE `naingwinaung93_car_rental`;

ALTER TABLE `reservation`
  ADD COLUMN IF NOT EXISTS `rental_mode` varchar(20) NOT NULL DEFAULT 'daily' AFTER `remark`,
  ADD COLUMN IF NOT EXISTS `pickup_datetime` varchar(50) DEFAULT NULL AFTER `rental_mode`,
  ADD COLUMN IF NOT EXISTS `return_datetime` varchar(50) DEFAULT NULL AFTER `pickup_datetime`,
  ADD COLUMN IF NOT EXISTS `rental_hours` decimal(10,2) NOT NULL DEFAULT 0 AFTER `return_datetime`;

ALTER TABLE `reservation_detail`
  ADD COLUMN IF NOT EXISTS `rate_mode` varchar(20) NOT NULL DEFAULT 'daily' AFTER `date`,
  ADD COLUMN IF NOT EXISTS `billing_units` decimal(10,2) NOT NULL DEFAULT 1 AFTER `rate_mode`,
  ADD COLUMN IF NOT EXISTS `unit_rate` decimal(10,2) DEFAULT NULL AFTER `billing_units`;

ALTER TABLE `reservation_delete`
  ADD COLUMN IF NOT EXISTS `rental_mode` varchar(20) NOT NULL DEFAULT 'daily' AFTER `remark`,
  ADD COLUMN IF NOT EXISTS `pickup_datetime` varchar(50) DEFAULT NULL AFTER `rental_mode`,
  ADD COLUMN IF NOT EXISTS `return_datetime` varchar(50) DEFAULT NULL AFTER `pickup_datetime`,
  ADD COLUMN IF NOT EXISTS `rental_hours` decimal(10,2) NOT NULL DEFAULT 0 AFTER `return_datetime`;

ALTER TABLE `reservation_detail_delete`
  ADD COLUMN IF NOT EXISTS `rate_mode` varchar(20) NOT NULL DEFAULT 'daily' AFTER `date`,
  ADD COLUMN IF NOT EXISTS `billing_units` decimal(10,2) NOT NULL DEFAULT 1 AFTER `rate_mode`,
  ADD COLUMN IF NOT EXISTS `unit_rate` decimal(10,2) DEFAULT NULL AFTER `billing_units`;
