<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class RelationTickets extends Model
{
    use HasFactory;

    protected $table = "tbl_relation_tickets";

    protected $fillable = [
        'idticket_parent',
        'iddticket_child',
        'status'
    ];

    protected $hidden = [
        'created_at',
        'updated_at'
    ];

    #Relaciones
    
    public function parent(): BelongsTo
    {
        return $this->belongsTo(Ticket::class, 'parent_ticket');
    }

    public function child(): BelongsTo
    {
        return $this->belongsTo(Ticket::class, 'child_ticket');
    }

    # Query scopes
    public function scopeActiveForID($query, $id)
    {
        return $query->where('id', $id)->where('status', 1);
    }

    public function scopeActive($query)
    {
        return $query->where('status', 1);
    }

}
