<?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\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use OwenIt\Auditing\Auditable as AuditingAuditable;
use OwenIt\Auditing\Contracts\Auditable;

class OrganizationUnit extends Model implements Auditable
{
    use HasFactory, SoftDeletes, AuditingAuditable;

    protected $guarded = [
        'deleted_at'
    ];

    protected $casts = [
        'updated_at' => 'date',
        'created_at' => 'date',
        'deleted_at' => 'date'
    ];

    public function dealership(): BelongsTo
    {
        return $this->belongsTo(Dealership::class, 'dealership_id');
    }

    public function group_division(): BelongsTo
    {
        return $this->belongsTo(Group::class, 'group_division_id');
    }

    public function division(): BelongsTo
    {
        return $this->belongsTo(Division::class, 'division_id');
    }

    public function department(): BelongsTo
    {
        return $this->belongsTo(Department::class, 'department_id');
    }

    public function section(): BelongsTo
    {
        return $this->belongsTo(Section::class, 'section_id');
    }

    public function unit(): BelongsTo
    {
        return $this->belongsTo(Unit::class, 'unit_id');
    }

    public function approver(): HasMany
    {
        return $this->hasMany(Approver::class, 'type_id');
    }
}
