<?php

namespace Modules\Travel\Entities;

use App\Models\User;
use App\Models\Travel\TravelType;
use App\Models\Traits\BranchTrait;
use App\Models\Traits\CompanyTrait;
use App\Models\coreApp\Status\Status;
use Illuminate\Database\Eloquent\Model;
use Modules\Travel\Entities\TravelPlan;
use Modules\Travel\Entities\TravelExpenseLog;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class TravelExpense extends Model
{
    use HasFactory, CompanyTrait, BranchTrait;

    protected $fillable = [
        'travel_plan_id',
        'travel_type_id',
        'date',
        'remark',
        'total_amount',
        'request_amount',
        'approval_amount',
        'status_id',
        'approved_by',
        'approved_at',
        'experience_rating',
        'created_by',
        'updated_by',
        'company_id',
        'branch_id',
    ];

    public function travelPlan()
    {
        return $this->belongsTo(TravelPlan::class);
    }

    public function status()
    {
        return $this->belongsTo(Status::class, 'status_id');
    }

    public function approvedBy()
    {
        return $this->belongsTo(User::class, 'approved_by');
    }

    public function travelExpenseLogs()
    {
        return $this->hasMany(TravelExpenseLog::class);
    }

    public function employee()
    {
        return $this->belongsTo(User::class, 'employee_id');
    }

    public function createdBy()
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    public function updatedBy()
    {
        return $this->belongsTo(User::class, 'updated_by');
    }
}
