<?php

namespace Kylin\Community\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Kylin\Community\Enums\RepairStatus;

/**
 * 报修工单
 */
class Repair extends Model
{
    protected $fillable = [
        'resident_id',
        'house_id',
        'category',
        'description',
        'status',
        'images',
        'assigned_to',
        'completed_at',
    ];

    protected function casts(): array
    {
        return [
            'status' => RepairStatus::class,
            'images' => 'array',
            'completed_at' => 'datetime',
        ];
    }

    public function resident(): BelongsTo
    {
        return $this->belongsTo(Resident::class);
    }

    public function house(): BelongsTo
    {
        return $this->belongsTo(House::class);
    }

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

    public function logs(): HasMany
    {
        return $this->hasMany(RepairLog::class);
    }
}
