<?php

namespace App\Models;

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

class Company extends Model
{
    use HasFactory;
    
    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'email',
        'name_english',
        'name_chinese',
        'registered_office_address_english',
        'registered_office_address_chinese',
        'br_number',
        'xero_api_key',
    ];

    public function getNameAttribute()
    {
        if (strtolower(app()->getLocale()) == 'zh_hk') {
            return $this->name_chinese;
        }
        return $this->name_english;
    }

    public function getRegisteredOfficeAddressAttribute()
    {
        if (strtolower(app()->getLocale()) == 'zh_hk') {
            return $this->registered_office_address_chinese;
        }
        return $this->registered_office_address_english;
    }

    public function users()
    {
        return $this->hasMany(User::class);
    }
}
