<?php

declare(strict_types=1);

namespace Kylin\Manufacturing\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Kylin\Manufacturing\Enums\InspectionType;
use Kylin\Manufacturing\Enums\InspectionResult;

/**
 * 检验记录
 */
class InspectionRecord extends Model
{
    protected $table = 'kylin_mfg_inspection_records';

    protected $fillable = [
        'inspection_no',
        'type',
        'work_order_id',
        'material_batch_no',
        'product_serial_no',
        'process_step',
        'standard_id',
        'result',
        'inspector_id',
        'inspected_at',
        'inspection_items',
        'remarks',
    ];

    protected function casts(): array
    {
        return [
            'type' => InspectionType::class,
            'result' => InspectionResult::class,
            'inspection_items' => 'array',
            'inspected_at' => 'datetime',
        ];
    }

    public function workOrder(): BelongsTo
    {
        return $this->belongsTo(WorkOrder::class);
    }

    public function standard(): BelongsTo
    {
        return $this->belongsTo(InspectionStandard::class, 'standard_id');
    }

    public function inspector(): BelongsTo
    {
        return $this->belongsTo(\App\Models\User::class, 'inspector_id');
    }
}
