<?php

declare(strict_types=1);

namespace Kylin\Manufacturing\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
 * 检验标准
 */
class InspectionStandard extends Model
{
    protected $table = 'kylin_mfg_inspection_standards';

    protected $fillable = [
        'name',
        'code',
        'type',
        'inspection_method',
        'standard_value',
        'tolerance',
        'aql_level',
        'sample_ratio',
        'status',
        'description',
    ];

    protected function casts(): array
    {
        return [
            'standard_value' => 'decimal:4',
            'tolerance' => 'decimal:4',
            'aql_level' => 'decimal:2',
            'sample_ratio' => 'decimal:4',
        ];
    }

    public function inspectionRecords(): HasMany
    {
        return $this->hasMany(InspectionRecord::class, 'standard_id');
    }
}
