import { BaseEntity } from "@edr/api-common";
import { SupportAuthorRole } from "@edr/types";
import { Column, Entity, Index } from "typeorm";

/** A single text message inside a {@link SupportConversation}. */
@Entity({ schema: "freight", name: "support_messages" })
@Index("IDX_SUPPORT_MSG_CONV_CREATED", ["conversationId", "createdAt"])
export class SupportMessage extends BaseEntity {
  @Column({ name: "conversation_id", type: "uuid" })
  conversationId!: string;

  @Column({ name: "author_user_id", type: "uuid" })
  authorUserId!: string;

  @Column({ name: "author_role", type: "varchar", length: 12 })
  authorRole!: SupportAuthorRole;

  /** Display name captured at send time (best-effort). */
  @Column({ name: "author_name", type: "varchar", length: 200, nullable: true })
  authorName?: string | null;

  /**
   * NULL for an attachment-only message. Nullable rather than "" so the absence
   * of text is representable instead of guessed at; the DTO maps NULL → "".
   */
  @Column({ name: "body", type: "text", nullable: true })
  body?: string | null;
}
