<?php

namespace App\Models;

use App\Enums\BudgetStatusType;
use App\Models\Traits\Filterable;
use App\Models\Traits\SelectOptions;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class BudgetDetail extends Model
{
  use HasFactory, Filterable, SelectOptions;

  protected $fillable = [
    'budget_id',
    'budget_category_id',
    'user_id',
    'code',
    'name',
    'description',
    'price',
    'price_total',
    'status',
    'status_message',
  ];

  protected $casts = [
    'status' => BudgetStatusType::class,
  ];

  public function quantityUnits()
  {
    return $this->hasMany(QuantityUnit::class);
  }

  public function unitType()
  {
    return $this->belongsTo(UnitType::class);
  }

  public function budget()
  {
    return $this->belongsTo(Budget::class, 'budget_id');
  }

  public function budgetCategory()
  {
    return $this->belongsTo(BudgetCategory::class);
  }

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

  public function transaction()
  {
    return $this->hasOne(Transaction::class, 'budget_detail_id');
  }

  public function approvalLogs()
  {
    return $this->hasMany(ApprovalLog::class, 'budget_detail_id');
  }
  public function reviewer()
  {
    return $this->belongsTo(User::class, 'user_review_id');
  }
}
