<?php

namespace Modules\Vrc\Entities;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

class VrcTicket extends Model
{
    protected $table = 'vrc_tickets';

    protected $fillable = [
        'business_id', 'location_id', 'number', 'erp_customer_id', 'vehicle_id', 'repair_order_id',
        'subject', 'description', 'category', 'priority', 'status', 'source',
        'assigned_to', 'ncr_id', 'opened_at', 'resolved_at',
    ];

    protected $casts = [
        'opened_at'   => 'datetime',
        'resolved_at' => 'datetime',
    ];

    public const STATUSES = ['open', 'assigned', 'in_progress', 'waiting_customer', 'resolved', 'closed'];

    public function messages(): HasMany
    {
        return $this->hasMany(VrcTicketMessage::class, 'ticket_id')->orderBy('id');
    }

    public function vehicle()
    {
        return $this->belongsTo(VrcVehicle::class, 'vehicle_id');
    }
}
