<?php

namespace App\Models;

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

class Ticket extends Model
{
    use HasFactory;

    protected $guarded = [];
    
    public function responses()
    {
        return $this->hasMany(Response::class, 'ticket_id', 'id');
    }
    
    public function notes()
    {
        return $this->hasMany(TicketNote::class, 'ticket_id', 'id');
    }
    
    public function lastResponse()
    {
        return $this->hasOne(Response::class)->latestOfMany();
    }
    
    public function comments()
    {
        return $this->hasMany(Comment::class, 'ticket_id', 'id')->orderBy('id', 'desc');
    }
}
