<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App\Models\Transaksi; 
use App\Models\Zone;

class Pelanggan extends Model
{
    protected $table = 'customers';
    protected $primaryKey = 'customers_id';
    public $incrementing = false;
    protected $keyType = 'string';

    protected $fillable = [
        'customers_id', 
        'name',
        'product_name',
        'phone', 
        'address',
        'kecamatan',
        'kabupaten',
        'id_zones',
        'titik_koordinat',
        'price_category'
    ]; 
    
    public function transaksi()
    {
        return $this->hasMany(Transaksi::class, 'customers_id', 'customers_id');
    }

    public function zone()
    {
        return $this->belongsTo(Zone::class, 'id_zones', 'id_zones');
    }

    // Tambahkan scope untuk filter pelanggan aktif
    public function scopeActive($query)
    {
        return $query->where('is_active', true)
                    ->orWhereNull('is_active');
    }
}