<?php

namespace Modules\Bms\Entities;

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

/**
 * A trackable fixed asset (chairs, tables, AV, décor). Carries identity
 * (code/QR), current location/hall, condition and a movement history. Managed
 * through AssetServiceContract so every relocation writes a movement audit.
 */
class BmsAsset extends Model
{
    protected $table = 'bms_assets';

    protected $fillable = [
        'business_id', 'code', 'name', 'name_ar', 'category',
        'location_id', 'hall_id', 'condition', 'status', 'quantity',
        'unit_value', 'serial_no', 'purchased_at', 'photo_path', 'notes',
    ];

    protected $casts = [
        'quantity'     => 'integer',
        'unit_value'   => 'decimal:2',
        'purchased_at' => 'date',
    ];

    public function hall(): BelongsTo
    {
        return $this->belongsTo(BmsHall::class, 'hall_id');
    }

    public function movements(): HasMany
    {
        return $this->hasMany(BmsAssetMovement::class, 'asset_id')->latest('id');
    }
}
