<?php

namespace App\Models;

use App\Traits\Multitenantable;
use DateTimeInterface;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Laravel\Sanctum\HasApiTokens;

class Customer extends Authenticatable
{
    use SoftDeletes, Multitenantable, HasApiTokens;

    protected $primaryKey = 'uuid';
    public $incrementing = false;
    protected $keyType = 'string';

    protected $fillable = [
        'uuid', 
        'tenant_id', 
        'outlet_id', 
        'name', 
        'email', 
        'phone_number', 
        'password', 
        'source'
    ];

    protected $casts = [
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
    ];

    protected $dates = ['deleted_at'];

    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    public function addresses(): HasMany 
    { 
        return $this->hasMany(CustomerAddress::class, 'customer_id', 'uuid'); 
    }
    public function orders(): HasMany 
    { 
        return $this->hasMany(Order::class, 'customer_id', 'uuid'); 
    }
}
