<?php

namespace HelpGent\App\Models;

defined( 'ABSPATH' ) || exit;

use HelpGent\App\Models\HelpGentUser;
use HelpGent\App\Models\Attachment;
use HelpGent\WpMVC\App;
use HelpGent\WpMVC\Database\Resolver;
use HelpGent\WpMVC\Database\Eloquent\Model;
use HelpGent\WpMVC\Database\Eloquent\Relations\BelongsToOne;

class ChatMessage extends Model {
    public static function get_table_name():string {
        return 'helpgent_chat_messages';
    }

    public function parent():BelongsToOne {
        return $this->belongs_to_one( ChatMessage::class, 'id', 'parent_id' );
    }

    public function user():BelongsToOne {
        return $this->belongs_to_one( HelpGentUser::class, 'id', 'created_by' );
    }

    public function attachment():BelongsToOne {
        return $this->belongs_to_one( Attachment::class, 'id', 'attachment_id' );
    }

    public function resolver():Resolver {
        return App::$container->get( Resolver::class );
    }
}