<?php

namespace App\Domain\Facility\Models;

use App\Domain\Shared\Traits\HasUuid;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class SpaceSegment extends Model
{
    use HasUuid;

    protected $fillable = [
        'space_layout_id',
        'code',
        'name',
        'name_ar',
        'row_index',
        'col_index',
        'lane_number',
        'area_sqm',
        'is_available',
        'capacity',
        'sort_order',
        'metadata',
    ];

    protected function casts(): array
    {
        return [
            'row_index' => 'integer',
            'col_index' => 'integer',
            'lane_number' => 'integer',
            'area_sqm' => 'decimal:2',
            'is_available' => 'boolean',
            'capacity' => 'integer',
            'sort_order' => 'integer',
            'metadata' => 'array',
        ];
    }

    public function layout(): BelongsTo
    {
        return $this->belongsTo(SpaceLayout::class, 'space_layout_id');
    }

    public function scopeAvailable($query)
    {
        return $query->where('is_available', true);
    }
}
