<?php

namespace Modules\Account\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Casts\Attribute;

class Bill extends Model
{
    use SoftDeletes;

    protected $table = 'account_bills';
    protected $fillable = [
        'user_id',
        'family_id',
        'type',
        'amount',
        'category',
        'remark',
        'bill_date'
    ];
    protected $dateFormat = 'Y-m-d H:i:s';

    protected function casts(): array
    {
        return [
            'bill_date' => 'date',
            'created_at' => 'datetime:Y-m-d H:i:s',
            'updated_at' => 'datetime:Y-m-d H:i:s',
            'deleted_at' => 'datetime:Y-m-d H:i:s',
        ];
    }

    /**
     * 账单所属用户
     */
    public function user()
    {
        return $this->belongsTo(\Modules\Member\Models\Member::class, 'user_id', 'uid');
    }

    /**
     * 账单所属家庭
     */
    public function family()
    {
        return $this->belongsTo(Family::class);
    }
}
