<?php

namespace App\Models;

use App\Models\Scopes\ModelScopes;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Validator;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Ticket extends Model
{
    use ModelScopes;
    use HasFactory;

    protected $table = 'tickets';

    protected $casts = [
        'created_at' => 'datetime:M d, Y h:m a',
    ];

    protected $fillable = [
        'user_id',
        'category_id',
        'ticket_id',
        'title',
        'message',
        'phone',
        'files',
        'status',
    ];
    public function validate($input = [])
    {
        $validate = Validator::make($input, [
            'category_id' => 'required',
            'title' => 'required',
            'message' => 'required',
            'phone' => 'required',
        ]);

        return $validate;
    }
    public function users()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }

    public function notifications()
    {
        return $this->hasMany(Notification::class, 'ticket_id');
    }

    public function comments()
    {
        return $this->hasMany(Comment::class, 'ticket_id');
    }
}
