<?php

namespace SoftminalB2B\Models;

if (!defined('ABSPATH')) {
    exit;
}

/**
 * A single line in a conversation ([[project-messaging-feature]]).
 *
 * author_type is 'buyer', 'shop', or 'system'. A system message (user_id 0)
 * records an event — a status change, a convert-to-quote — straight into the
 * thread, so the read cursors on the conversation cover events as well as chat
 * and the thread doubles as a negotiation audit trail.
 *
 * @property int    $id
 * @property int    $conversation_id
 * @property int    $user_id     Author; 0 for a system line.
 * @property string $author_type buyer|shop|system
 * @property string $body
 * @property string $created_at
 */
class Message extends Model
{
    protected $table = 'messages';

    // messages is insert-only — a line is never edited, so there is no
    // updated_at column for the base save() to touch.
    protected $timestamps = true;
    protected $updatedAtColumn = null;

    protected $fillable = [
        'conversation_id',
        'user_id',
        'author_type',
        'body',
    ];

    public const AUTHOR_BUYER  = 'buyer';
    public const AUTHOR_SHOP   = 'shop';
    public const AUTHOR_SYSTEM = 'system';
}
