<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Account extends Model
{
    use HasFactory;

    protected $fillable = ['number', 'user_id','office_id', 'balance', 'currency_code', 'status'];

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function office()
    {
        return $this->belongsTo(Office::class);
    }

    public function  getOwnerAttribute(){
        if($this->office)return $this->office;
        if($this->user)return $this->user;
        return null;
    }
    
}
