-- Migration 008: Tabela de mensagens do WhatsApp
CREATE TABLE IF NOT EXISTS mensagens (
  id          SERIAL PRIMARY KEY,
  wamid       VARCHAR(255) NOT NULL,
  chat_id     VARCHAR(255) NOT NULL,
  from_me     BOOLEAN      NOT NULL DEFAULT FALSE,
  type        VARCHAR(50)  NOT NULL,
  body        TEXT,
  sender_name VARCHAR(255),
  status      VARCHAR(50),
  timestamp   BIGINT       NOT NULL,
  created_at  TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
  UNIQUE (wamid)
);

CREATE INDEX IF NOT EXISTS idx_mensagens_chat_id   ON mensagens (chat_id);
CREATE INDEX IF NOT EXISTS idx_mensagens_timestamp ON mensagens (timestamp DESC);
