<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Contact extends Model
{
    protected $fillable = [
        'business_id', 'name', 'email', 'phone', 'address', 'tax_number',
        'is_supplier', 'is_customer', 'is_active',
    ];

    protected $casts = [
        'is_supplier' => 'boolean',
        'is_customer' => 'boolean',
        'is_active' => 'boolean',
    ];

    public function toArray(): array
    {
        $a = parent::toArray();
        $a['businessId']  = $a['business_id']  ?? null;
        $a['taxNumber']   = $a['tax_number']   ?? null;
        $a['isSupplier']  = (bool) ($a['is_supplier'] ?? false);
        $a['isCustomer']  = (bool) ($a['is_customer'] ?? false);
        $a['isActive']    = (bool) ($a['is_active']   ?? true);
        return $a;
    }

    public function business(): BelongsTo { return $this->belongsTo(Business::class); }
}
