<?php

namespace App\Models;

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

class Customer extends Model
{
    use HasFactory;

    protected $table = 'customers';

    protected $fillable = [
        'id',
        'entity_type',
        'created_time',
        'country',
        'state',
        'city',
        'address',
        'address2',
        'zip',
        'phone',
        'email',
        'title',
        'tenant_id',
        'external_id',
        'version',
        'name',
        'additional_info',
        'country_xid',
        'state_xid',
        'city_xid',
    ];

    protected $casts = [
        'id' => 'string',
        'tenant_id' => 'string',
        'external_id' => 'string',
        'additional_info' => 'array',
    ];


    public function assets()
{
    return $this->hasMany(Asset::class, 'customer_id', 'id');
}

public function devices()
{
    return $this->hasManyThrough(
        Device::class,        // Final model
        Asset::class,         // Intermediate model
        'customer_id',        // FK on Asset table
        'asset_id',           // FK on Device table
        'id',                 // Local key on Customer table
        'id'                  // Local key on Asset table
    );
}

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