<?php

namespace App\Models;

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

class FieldCondition extends Model
{
    use HasFactory;

    protected $fillable = [
        'category_id', 
        'attribute_id',
        'target_field_id', 
        'operator', 
        'value',
        'field_id',
        'source_field_id',
    ];

    public function category()
    {
        return $this->belongsTo(Category::class);
    }

    /**
     * Get the field that is being shown or hidden based on the condition.
     */
    public function field()
    {
        return $this->belongsTo(CategoryField::class, 'field_id');
    }

    /**
     * Get the related field that is used to trigger the condition.
     */
    public function relatedField()
    {
        return $this->belongsTo(CategoryField::class, 'target_field_id');
    }
}
