<?php

namespace Modules\Lpj\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Modules\Usermanagement\Models\User;

class Authorization extends Model
{
    protected $table = 'authorizations';

    protected $fillable = [
        'permohonan_id',
        'jenis',
        'approve_so',
        'status_so',
        'keterangan_so',
        'approve_so_at',
        'approve_eo',
        'status_eo',
        'keterangan_eo',
        'approve_eo_at',
        'approve_dd',
        'status_dd',
        'keterangan_dd',
        'approve_dd_at',
        'status',
        'keterangan',
        'request',
        'alasan',
        'user_id',
    ];

    protected $casts = [
        // 'approve_so' => 'boolean',
        // 'approve_eo' => 'boolean',
        // 'approve_dd' => 'boolean',
        'approve_so_at' => 'datetime',
        'approve_eo_at' => 'datetime',
        'approve_dd_at' => 'datetime',
    ];

    /**
     * Get the permohonan that owns the authorization.
     */
    public function permohonan(): BelongsTo
    {
        return $this->belongsTo(Permohonan::class);
    }

    /**
     * Get the user that owns the authorization.
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    public function approveEo(){
        return $this->belongsTo(User::class, 'approve_eo', 'id');
    }

    public function approveDd(){
        return $this->belongsTo(User::class, 'approve_dd', 'id');
    }

    public function approveSo(){
        return $this->belongsTo(User::class, 'approve_so', 'id');
    }
}
