
CREATE TABLE IF NOT EXISTS app_media (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    slot ENUM('LOGIN_HERO','HOME_TOP','HOME_MIDDLE','RIDES_TOP','PROFILE_TOP','ADMIN_TOP') NOT NULL,
    title VARCHAR(180) NULL,
    subtitle VARCHAR(500) NULL,
    image_path VARCHAR(500) NOT NULL,
    target_url VARCHAR(500) NULL,
    status ENUM('ACTIVE','INACTIVE') NOT NULL DEFAULT 'ACTIVE',
    sort_order INT NOT NULL DEFAULT 0,
    created_by BIGINT UNSIGNED NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    INDEX idx_app_media_slot (slot,status,sort_order),
    CONSTRAINT fk_app_media_admin FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS ride_proofs (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    ride_id BIGINT UNSIGNED NOT NULL,
    user_id BIGINT UNSIGNED NOT NULL,
    type ENUM('ACCEPTED','ARRIVED','COMPLETED','CUSTOMER_CANCEL','OTHER') NOT NULL,
    image_path VARCHAR(500) NOT NULL,
    note VARCHAR(500) NULL,
    latitude DECIMAL(10,7) NULL,
    longitude DECIMAL(10,7) NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_ride_proofs_ride (ride_id,type,created_at),
    CONSTRAINT fk_ride_proof_ride FOREIGN KEY (ride_id) REFERENCES rides(id) ON DELETE CASCADE,
    CONSTRAINT fk_ride_proof_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
