<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class RoomInspection extends Model
{
    use \App\Models\Concerns\BelongsToHotel;

    protected $guarded = [];
    protected $casts = [
        'inspected_at' => 'datetime',
    ];

    public function room()
    {
        return $this->belongsTo(Room::class);
    }

    public function inspector()
    {
        return $this->belongsTo(User::class, 'inspected_by');
    }

    public function housekeepingTask()
    {
        return $this->belongsTo(HousekeepingTask::class);
    }

    public function items()
    {
        return $this->hasMany(RoomInspectionItem::class);
    }

    public function issueCount(): int
    {
        return $this->items()->where('condition', '!=', 'intact')->count();
    }
}
