<?php

namespace App\Models\Commons;

use App\Traits\Auditable;
use App\Traits\BelongsToTenant;
use App\Traits\ModelTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class CategoryField extends Model
{
    use Auditable, BelongsToTenant, ModelTrait, SoftDeletes;

    protected $table = 'category_fields';

    protected $fillable = [
        'tenant_id', 'category_id',
        'field_key', 'field_name', 'field_type',
        'is_required', 'sort_order', 'default_value', 'options', 'description',
        'created_by', 'updated_by', 'deleted_by',
    ];

    protected $casts = [
        'is_required' => 'boolean',
        'sort_order' => 'integer',
        'options' => 'array',
    ];

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

    // 편의 스코프
    public function scopeRequired($q)
    {
        return $q->where('is_required', true);
    }
}
