<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class SupportTicketReply extends Model
{
    public function attachments()
    {
        return $this->hasMany(SupportTicketAttachment::class);
    }

    public function admin()
    {
        return $this->belongsTo(Admin::class);
    }

    public function supportTicket()
    {
        return $this->belongsTo(SupportTicket::class);
    }

    public function getImagePath()
    {
        $imagePath = $this->admin_id ? getImage(getFilePath('adminProfile') . '/' . $this->admin->image, avatar : true): getImage(getFilePath('userProfile') . '/' . $this->supportTicket->user->image, avatar: true);
        return $imagePath;
    }

    public function getName()
    {
        $name = $this->admin_id ? $this->admin->name : $this->supportTicket->user->fullname;
        return $name;
    }

    public function getRoute()
    {
        $route = $this->admin_id ? route('admin.agent.overview', $this->admin_id) : route('admin.customer.overview', $this->supportTicket->user_id);
        return $route;
    }

}
