-- Customers Table
CREATE TABLE customers (
    tenant_id UUID,
    customer_id UUID,
    name VARCHAR(100) NOT NULL,
    contact_info JSONB,
    PRIMARY KEY (tenant_id, customer_id),
    FOREIGN KEY (tenant_id) REFERENCES tenants(id)
);
-- Projects Table
CREATE TABLE projects (
    tenant_id UUID,
    project_id UUID,
    customer_id UUID,
    name VARCHAR(100) NOT NULL,
    description TEXT NOT NULL,
    status VARCHAR(50) NOT NULL,
    deadline TIMESTAMP,
    progress NUMERIC(5, 2),
    vector_embedding VECTOR(768), -- Adjust the dimensions as needed
    PRIMARY KEY (tenant_id, project_id),
    FOREIGN KEY (tenant_id, customer_id) REFERENCES customers(tenant_id, customer_id)
);
-- Support Members Table
CREATE TABLE support_members (
    tenant_id UUID,
    support_member_id UUID,
    PRIMARY KEY (tenant_id, support_member_id),
    FOREIGN KEY (tenant_id, support_member_id) REFERENCES users.tenant_users(tenant_id, user_id)
);
-- Tasks Table
CREATE TABLE tasks (
    tenant_id UUID,
    task_id UUID,
    project_id UUID,
    assigned_to UUID, -- Can be either customer or support member
    description TEXT NOT NULL,
    status VARCHAR(50) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    completed_at TIMESTAMP,
    vector_embedding VECTOR(768), -- Adjust the dimensions as needed
    PRIMARY KEY (tenant_id, task_id),
    FOREIGN KEY (tenant_id, project_id) REFERENCES projects(tenant_id, project_id),
    FOREIGN KEY (tenant_id, assigned_to) REFERENCES users.tenant_users(tenant_id, user_id)
);
-- Knowledge Base Table
CREATE TABLE knowledge_base (
    tenant_id UUID,
    article_id UUID,
    title VARCHAR(100) NOT NULL,
    content TEXT NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    vector_embedding VECTOR(768), -- Adjust the dimensions as needed
    PRIMARY KEY (tenant_id, article_id),
    FOREIGN KEY (tenant_id) REFERENCES tenants(id)
);
-- Notifications Table
CREATE TABLE notifications (
    tenant_id UUID,
    notification_id UUID,
    recipient_id UUID, -- Sales leader or any designated role
    message TEXT NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    is_read BOOLEAN DEFAULT FALSE,
    PRIMARY KEY (tenant_id, notification_id),
    FOREIGN KEY (tenant_id, recipient_id) REFERENCES users.tenant_users(tenant_id, user_id)
);