<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class EcaNotification extends Model
{
    // ── Points to notifications table ──
    protected $table = 'notifications';

    protected $fillable = [
        'user_id',
        'title',
        'message',
        'type',
        'is_read',
    ];

    protected $casts = [
        'is_read' => 'boolean',
    ];

    // ── RELATIONSHIP ──
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id');
    }

    // ─────────────────────────────────
    // STATIC HELPER — Send Notification
    // Usage:
    // EcaNotification::send(
    //     $userId,
    //     'Title here',
    //     'Message here',
    //     'INFO'
    // );
    // ─────────────────────────────────
    public static function send(
        int    $userId,
        string $title,
        string $message,
        string $type = 'INFO'
    ): self {
        return self::create([
            'user_id' => $userId,
            'title'   => $title,
            'message' => $message,
            'type'    => $type,
            'is_read' => false,
        ]);
    }
}