<?php

namespace Modules\Travel\Entities;

use App\Models\User;
use App\Models\Upload;
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\TravelExpense;
use Modules\Travel\Entities\TravelMeeting;
use Modules\Travel\Entities\TravelWorkflow;
use Illuminate\Database\Eloquent\Factories\HasFactory;

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

    protected $fillable = [
        'employee_id',
        'from_date',
        'to_date',
        'from_location',
        'to_location',
        'purpose',
        'amount',
        'signature_id',
        'signature_date',
        'status_id',
        'approved_by',
        'approved_at',
        'approved_remark',
        'rejected_by',
        'rejected_at',
        'rejected_remark',
        'created_by',
        'updated_by',
        'company_id',
        'branch_id',
    ];

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

    public function signature()
    {
        return $this->belongsTo(Upload::class, 'signature_id');
    }

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

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

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

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

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

    public function travelMeetings()
    {
        return $this->hasMany(TravelMeeting::class);
    }

    public function travelExpenses()
    {
        return $this->hasMany(TravelExpense::class);
    }

    public function travelWorkflows()
    {
        return $this->hasMany(TravelWorkflow::class);
    }
}
