<?php

namespace App\Models\InternationalTour;

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

class InternationalTourTransferPoint extends Model
{
    use HasFactory;

    protected $table = 'international_tour_transfer_points';

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

    protected function casts(): array
    {
        return [
            'is_active' => 'boolean',
            'latitude' => 'decimal:8',
            'longitude' => 'decimal:8',
        ];
    }

    public function tour()
    {
        return $this->belongsTo(InternationalTour::class, 'international_tour_id');
    }

    public function scopeActive($query)
    {
        return $query->where('is_active', true);
    }

    public function scopeDeparturePoints($query)
    {
        return $query->where('point_type', 'departure');
    }

    public function scopeTransferPoints($query)
    {
        return $query->where('point_type', 'transfer');
    }

    public function scopeOrdered($query)
    {
        return $query->orderBy('sort_order');
    }
}
