<?php
namespace App\Models;
use CodeIgniter\Model;

class CustomerAddressModel extends Model
{
    protected $table          = 'customer_addresses';
    protected $primaryKey     = 'id';
    protected $useSoftDeletes = false;
    protected $deletedField   = 'deleted_at';
    protected $allowedFields  = ['customer_id','type','label','line1','line2','line3','town','county','postcode','country','what3words','access_notes','is_primary','is_default','created_at','updated_at','deleted_at'];

    public function forCustomer(int $id, string $type = null): array
    {
        $b = $this->where('customer_id', $id)->whereNull('deleted_at');
        if ($type) $b->where('type', $type);
        return $b->findAll();
    }
}
