<?php

namespace Kylin\Community\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

/**
 * 房产模型
 *
 * 智慧社区房产信息，管理小区楼栋、单元、房间及住户关联。
 */
class House extends Model
{
    protected $fillable = [
        'building',
        'unit',
        'room',
        'area',
        'type',
        'status',
    ];

    protected function casts(): array
    {
        return [
            'area' => 'decimal:2',
        ];
    }

    public function residents(): BelongsToMany
    {
        return $this->belongsToMany(Resident::class, 'resident_house')
            ->withPivot('relation', 'is_owner')
            ->withTimestamps();
    }
}
