<?php

declare(strict_types=1);

namespace Kylin\Manufacturing\Models;

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

/**
 * 维修工单
 */
class RepairOrder extends Model
{
    protected $table = 'kylin_mfg_repair_orders';

    protected $fillable = [
        'repair_no',
        'equipment_id',
        'reporter_id',
        'assignee_id',
        'fault_description',
        'fault_type',
        'repair_method',
        'status',
        'reported_at',
        'completed_at',
    ];

    protected function casts(): array
    {
        return [
            'reported_at' => 'datetime',
            'completed_at' => 'datetime',
        ];
    }

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

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

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