<?php

namespace App\Models\Inventory;

use App\Models\Concerns\BelongsToTenant;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class SerialRepairHistory extends Model
{
    use BelongsToTenant;

    protected $table = 'serial_repair_history';

    protected $fillable = [
        'product_serial_id', 'branch_id', 'description',
        'repair_cost', 'repaired_by', 'started_at', 'completed_at',
        'outcome', 'notes', 'created_by',
    ];

    protected function casts(): array
    {
        return [
            'repair_cost' => 'decimal:2',
            'started_at' => 'date',
            'completed_at' => 'date',
        ];
    }

    public function serial(): BelongsTo
    {
        return $this->belongsTo(ProductSerial::class, 'product_serial_id');
    }

    public function createdBy(): BelongsTo
    {
        return $this->belongsTo(User::class, 'created_by');
    }
}
