<?php

namespace App\Models;

use App\Models\BaseModel;

class CommunicationLog extends BaseModel
{
    protected $table = 'communication_logs';

    // CI model didn't enable timestamps; keep off unless your table has created_at/updated_at.
    public $timestamps = false;

    protected $fillable = [
        'student_id',
        'family_id',
        'student_name',
        'template_key',
        'subject',
        'body',
        'recipients',
        'cc',
        'bcc',
        'attachments',
        'status',
        'error_message',
        'sent_by',
        'metadata',
    ];

    public function getFillable(): array
    {
        return $this->fillable;
    }

    protected $casts = [
        'student_id'   => 'integer',
        'family_id'    => 'integer',
        'sent_by'      => 'integer',

        // If these columns are JSON in DB, this will auto convert to arrays
        'recipients'   => 'array',
        'cc'           => 'array',
        'bcc'          => 'array',
        'attachments'  => 'array',
        'metadata'     => 'array',
    ];

    /* Optional relationships */
    public function student()
    {
        return $this->belongsTo(Student::class, 'student_id');
    }

    public function sender()
    {
        return $this->belongsTo(User::class, 'sent_by');
    }
}
