<?php

namespace App\Models;

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

class ReplacementReport extends Model
{
    use HasIndonesianTimestamps;

    public const CREATED_AT = 'dibuat_pada';
    public const UPDATED_AT = 'diperbarui_pada';

    protected $fillable = [
        'id_pengguna',
        'id_barang',
        'jenis_laporan',
        'catatan_kerusakan',
        'lokasi_foto',
        'status_laporan',
    ];

    public function inventoryItem(): BelongsTo
    {
        return $this->belongsTo(InventoryItem::class, 'id_barang');
    }

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

    public function getUserIdAttribute(): ?int
    {
        return $this->attributes['id_pengguna'] ?? null;
    }

    public function getInventoryItemIdAttribute(): ?int
    {
        return $this->attributes['id_barang'] ?? null;
    }

    public function getTypeAttribute(): ?string
    {
        return $this->attributes['jenis_laporan'] ?? null;
    }

    public function getDamageNoteAttribute(): ?string
    {
        return $this->attributes['catatan_kerusakan'] ?? null;
    }

    public function getPhotoPathAttribute(): ?string
    {
        return $this->attributes['lokasi_foto'] ?? null;
    }

    public function getStatusAttribute(): ?string
    {
        return $this->attributes['status_laporan'] ?? null;
    }
}
