<?php

namespace App\Models\Invoicing;

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

class TaxBranch extends Model {
  //* Associated Table & Primary Key
    protected $table = 'tax_branches';
    protected $primaryKey = 'id';

  //* Fillable Fields
    protected $fillable = [
        'legal_name',
        'email',
        'zip',
        'tax_address',
        'sample_address',
    ];

  //* Cast Columns
    protected $casts = [
        'tax_address'      => 'array',   // Example of structure on resources\json\modules\invoices\tax_address_structure.json
    ];

  //* Relationships
    public function taxInvoices() {
        return $this->hasMany(TaxInvoice::class);
    }

    public function taxPayments() {
        return $this->hasMany(TaxPayment::class);
    }

  //* Rules
    protected static function booted()
    {
        static::updating(function ($model) {
            unset($model->legal_name);
        });
    }
}
