<?php

namespace App\Models\Design;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class BomTemplate extends Model
{
    use SoftDeletes;

    protected $table = 'bom_templates';

    protected $fillable = [
        'tenant_id', 'model_version_id', 'name', 'is_primary', 'notes',
        'calculation_schema', 'company_type', 'formula_version',
    ];

    protected $casts = [
        'is_primary' => 'boolean',
        'calculation_schema' => 'array',
    ];

    public function modelVersion()
    {
        return $this->belongsTo(ModelVersion::class, 'model_version_id');
    }

    public function items()
    {
        return $this->hasMany(BomTemplateItem::class, 'bom_template_id');
    }
}
