<?php

namespace App\Models;

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

class ImportRow extends Model
{
    use HasFactory;

    protected $fillable = [
        'import_batch_id',
        'sheet_name',
        'row_number',
        'location_name',
        'item_name',
        'raw_quantity',
        'normalized_quantity',
        'good_count',
        'minor_damage_count',
        'major_damage_count',
        'update_date',
        'row_type',
        'review_status',
        'notes',
        'raw_payload',
        'issue_notes',
        'final_item_id',
        'final_facility_object_id',
    ];

    protected $casts = [
        'update_date' => 'datetime',
        'raw_payload' => 'array',
    ];

    public function batch(): BelongsTo
    {
        return $this->belongsTo(ImportBatch::class, 'import_batch_id');
    }

    public function finalItem(): BelongsTo
    {
        return $this->belongsTo(Item::class, 'final_item_id');
    }

    public function finalFacilityObject(): BelongsTo
    {
        return $this->belongsTo(FacilityObject::class, 'final_facility_object_id');
    }
}
