<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class VehicleLog extends Model
{
    use HasFactory, SoftDeletes;

    protected $fillable = [
        'tenant_id',
        'vehicle_id',
        'log_date',
        'department',
        'driver_name',
        'trip_type',
        'departure_type',
        'departure_name',
        'departure_address',
        'arrival_type',
        'arrival_name',
        'arrival_address',
        'distance_km',
        'note',
    ];

    protected $casts = [
        'log_date' => 'date',
        'distance_km' => 'integer',
    ];

    /**
     * 차량 관계
     */
    public function vehicle(): BelongsTo
    {
        return $this->belongsTo(CorporateVehicle::class, 'vehicle_id');
    }

    /**
     * 테넌트 관계
     */
    public function tenant(): BelongsTo
    {
        return $this->belongsTo(Tenant::class);
    }

    /**
     * 구분(trip_type) 목록
     */
    public static function getTripTypes(): array
    {
        return [
            'commute_to' => '출근용',
            'commute_from' => '퇴근용',
            'business' => '업무용',
            'personal' => '비업무',
        ];
    }

    /**
     * 분류(location_type) 목록
     */
    public static function getLocationTypes(): array
    {
        return [
            'home' => '자택',
            'office' => '회사',
            'client' => '거래처',
            'other' => '기타',
        ];
    }

    /**
     * 비고 목록
     */
    public static function getNoteOptions(): array
    {
        return [
            '거래처방문',
            '제조시설등',
            '회의참석',
            '판촉활동',
            '교육등',
        ];
    }
}
