<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

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

    protected $guarded = [];
    protected $casts = ['scheduled_for' => 'date', 'completed_at' => 'datetime', 'started_at' => 'datetime'];

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

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

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

    public function elapsedMinutes(): ?int
    {
        return $this->duration_minutes ?? ($this->started_at ? $this->started_at->diffInMinutes($this->completed_at ?? now()) : null);
    }
}
