<?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\PaymentStatus;

/**
 * 物业缴费
 */
class Payment extends Model
{
    protected $fillable = [
        'resident_id',
        'house_id',
        'type',
        'amount',
        'period',
        'status',
        'due_date',
        'paid_at',
    ];

    protected function casts(): array
    {
        return [
            'amount' => 'decimal:2',
            'status' => PaymentStatus::class,
            'due_date' => 'date',
            'paid_at' => 'datetime',
        ];
    }

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

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

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