<?php

namespace App\Models\Products;

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

/**
 * @mixin IdeHelperCommonCode
 */
class CommonCode extends Model
{
    use BelongsToTenant, ModelTrait, SoftDeletes;

    protected $table = 'common_codes';

    protected $fillable = [
        'tenant_id',
        'code_group',
        'code',
        'name',
        'parent_id',
        'attributes',
        'description',
        'is_active',
        'sort_order',
    ];

    protected $casts = [
        'attributes' => 'array',
        'is_active' => 'boolean',
    ];

    // 관계: 상위 코드
    public function parent()
    {
        return $this->belongsTo(self::class, 'parent_id');
    }

    // 관계: 하위 코드들
    public function children()
    {
        return $this->hasMany(self::class, 'parent_id');
    }
}
