CREATE TABLE IF NOT EXISTS `bookings` (
    `id`             INT UNSIGNED NOT NULL AUTO_INCREMENT,
    `uuid`           CHAR(36) NOT NULL COMMENT 'Public-facing booking ID',
    `client_id`      INT UNSIGNED NOT NULL,
    `therapist_id`   INT UNSIGNED NOT NULL,
    `service_id`     INT UNSIGNED NOT NULL,
    `booked_at`      DATETIME NOT NULL COMMENT 'Scheduled date+time',
    `duration_min`   SMALLINT UNSIGNED NOT NULL,
    `price_cents`    INT UNSIGNED NOT NULL,
    `fee_cents`      INT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Platform commission',
    `currency`       CHAR(3) NOT NULL DEFAULT 'EUR',
    `status`         ENUM('pending','confirmed','completed','cancelled','no_show') NOT NULL DEFAULT 'pending',
    `location_type`  ENUM('salon','home','other') NOT NULL DEFAULT 'salon',
    `address`        VARCHAR(255) NULL COMMENT 'Client address for home visits',
    `notes`          TEXT NULL,
    `cancelled_by`   INT UNSIGNED NULL COMMENT 'User ID who cancelled',
    `cancel_reason`  VARCHAR(255) NULL,
    `payment_status` ENUM('unpaid','paid','refunded') NOT NULL DEFAULT 'unpaid',
    `payment_method` VARCHAR(50) NULL,
    `paid_at`        DATETIME NULL,
    `reviewed`       TINYINT(1) NOT NULL DEFAULT 0,
    `created_at`     DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at`     DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`),
    UNIQUE KEY `bookings_uuid_unique` (`uuid`),
    KEY `bookings_client_id_index` (`client_id`),
    KEY `bookings_therapist_id_index` (`therapist_id`),
    KEY `bookings_status_index` (`status`),
    KEY `bookings_booked_at_index` (`booked_at`),
    CONSTRAINT `fk_bk_client`    FOREIGN KEY (`client_id`)    REFERENCES `users` (`id`),
    CONSTRAINT `fk_bk_therapist` FOREIGN KEY (`therapist_id`) REFERENCES `therapist_profiles` (`id`),
    CONSTRAINT `fk_bk_service`   FOREIGN KEY (`service_id`)   REFERENCES `services` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
