<?php

namespace Modules\Account\Models;

use App\Models\BaseModel;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Casts\Attribute;

class Bill extends BaseModel
{
    use SoftDeletes;

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

    protected function casts(): array
    {
        return [
            'date' => 'datetime:Y-m-d',
            'bill_date' => 'datetime:Y-m-d',
            '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);
    }
}
