<?php

namespace App\Models\OLDLMS;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;

class Livechat extends Model
{
    use HasFactory;


    public $sStatusNames = [
        0 => 'Menunggu Konfirmasi',
        1 => 'Diterima',
        2 => 'Ditolak',
        3 => 'Selesai',
        4 => 'Expired',
    ];

    const CREATED_AT = 'dCreateOn';
    const UPDATED_AT = 'dUpdateOn';
    const DELETED_AT = 'dDeleteOn';

    protected $connection = 'oldlms';

    protected $table = 'tx_livechat';

    protected $appends = [
        'status_name',
    ];

    protected function statusName(): Attribute
    {
        return Attribute::make(
            get: function ($value) {
                return $this->sStatusNames[$this->sStatus] ?? '-';
            },
        );
    }


    public function user()
    {
        return $this->belongsTo(User::class, 'nIDUser', 'nID');
    }

    public function doctor()
    {
        return $this->belongsTo(Dokter::class, 'nIDDokter', 'nID');
    }


    public function appointment()
    {
        return $this->belongsTo(Appointment::class, 'nIDAppointment', 'nID');
    }

    public function healthCare()
    {
        return $this->belongsTo(Healthcare::class, 'nIDHealthCare', 'nID');
    }
}
