-- Migration 024: Persistência de mensagens WhatsApp (Meta API)
CREATE TABLE mensagens (
  id          SERIAL PRIMARY KEY,
  wamid       VARCHAR(255) UNIQUE NOT NULL,
  chat_id     VARCHAR(50)  NOT NULL,
  from_me     BOOLEAN      NOT NULL DEFAULT FALSE,
  type        VARCHAR(50)  NOT NULL DEFAULT 'text',
  body        TEXT,
  sender_name VARCHAR(255),
  status      VARCHAR(20),
  timestamp   BIGINT       NOT NULL,
  created_at  TIMESTAMP    NOT NULL DEFAULT NOW()
);

CREATE INDEX idx_mensagens_chat_id  ON mensagens(chat_id);
CREATE INDEX idx_mensagens_timestamp ON mensagens(timestamp);
