<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Lease extends Model
{
    //

    protected $fillable = [

        'lease_no',

        'device_id',

        'lease_type',

        'customer_id',

        'customer_name',

        'sub_t1_no',

        'truck_no',

        'trailer_no',

        'driver_name',

        'driver_phone',

        'passport_or_license',

        'cargo_type',

        'agent_name',

        'destination_border_id',

        'tag_point_id',

        'amount',

        'sales_user_id',

        'status',

        'audited_at',

        'audited_by',

        'audit_notes',

        'leased_at',

        'returned_at',

        'created_by',

        'updated_by',

        'cancelled_by',
        'cancelled_at',
        'cancel_reason',
        
    ];



    protected $casts = [

        'leased_at' => 'datetime',

        'returned_at' => 'datetime',

        'audited_at' => 'datetime',

        'created_at' => 'datetime',

        'updated_at' => 'datetime',

    ];





    public function device()
    {
        return $this->belongsTo(Device::class);
    }

    public function customer()
    {
        return $this->belongsTo(Customer::class);
    }

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

    public function destination()
    {
        return $this->belongsTo(BorderStation::class, 'destination_border_id');
    }

    public function tagPoint()
    {
        return $this->belongsTo(TagPoint::class);
    }


    public function deviceSwaps()
    {
        return $this->hasMany(
            LeaseDeviceSwap::class
        );
    }
}
