<?php

return <<<'SQL'
CREATE TABLE support_request_messages (
    id CHAR(36) NOT NULL PRIMARY KEY,
    support_request_id CHAR(36) NOT NULL,
    tenant_id CHAR(36) NOT NULL,
    author_user_id CHAR(36) NULL,
    author_tenant_user_id CHAR(36) NULL,
    author_name VARCHAR(255) NOT NULL,
    author_role VARCHAR(50) NOT NULL DEFAULT 'member',
    message_kind VARCHAR(50) NOT NULL DEFAULT 'public_reply',
    new_status VARCHAR(50) NULL,
    body TEXT NOT NULL,
    created_at DATETIME NOT NULL,
    KEY support_request_messages_request_index (support_request_id, created_at),
    KEY support_request_messages_tenant_index (tenant_id),
    FOREIGN KEY (support_request_id) REFERENCES support_requests(id) ON DELETE CASCADE,
    FOREIGN KEY (tenant_id) REFERENCES tenants(id),
    FOREIGN KEY (author_user_id) REFERENCES users(id),
    FOREIGN KEY (author_tenant_user_id) REFERENCES tenant_users(id)
);
SQL;
