<?php

namespace App\Models\Tour;

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

class TourTransferPoint extends Model
{
    use HasFactory;

    protected $table = 'cultural_tour_transfer_points';

    protected $fillable = [
        'cultural_tour_id',
        'point_type',
        'location_name',
        'address',
        'pickup_time',
        'sort_order',
        'latitude',
        'longitude',
        'notes',
        'is_active',
    ];

    protected function casts(): array
    {
        return [
            'pickup_time' => 'datetime:H:i',
            'latitude' => 'decimal:8',
            'longitude' => 'decimal:8',
            'is_active' => 'boolean',
            'sort_order' => 'integer',
        ];
    }

    /**
     * Tour ilişkisi
     */
    public function tour()
    {
        return $this->belongsTo(Tour::class, 'cultural_tour_id');
    }

    /**
     * Scope: Sadece kalkış noktaları
     */
    public function scopeDeparturePoints($query)
    {
        return $query->where('point_type', 'departure')->orderBy('sort_order');
    }

    /**
     * Scope: Sadece transfer noktaları
     */
    public function scopeTransferPoints($query)
    {
        return $query->where('point_type', 'transfer')->orderBy('sort_order');
    }

    /**
     * Scope: Aktif noktalar
     */
    public function scopeActive($query)
    {
        return $query->where('is_active', true);
    }
}
