<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Language extends Model
{
    protected $table = 'languages';
    
    // Disable Laravel's default timestamps (we're using created_at_utc, updated_at_utc)
    public $timestamps = false;

    protected $fillable = [
        'code',
        'name_en',
        'name_native',
        'is_active',
        'is_default',
        'status',
        'created_at_utc',
        'updated_at_utc',
        'created_by',
        'updated_by',
        'deleted_at_utc',
        'deleted_by',
    ];

    protected $casts = [
        'is_active' => 'boolean',
        'is_default' => 'boolean',
        'created_at_utc' => 'datetime',
        'updated_at_utc' => 'datetime',
        'deleted_at_utc' => 'datetime',
    ];

    /**
     * Scope: Get only active languages
     */
    public function scopeActive($query)
    {
        return $query->where('is_active', true)
                     ->where('status', 'active');
    }

    /**
     * Scope: Get only non-deleted records (soft deletes)
     */
    public function scopeNotDeleted($query)
    {
        return $query->whereNull('deleted_at_utc');
    }

    /**
     * Get the employee who created this language
     */
    public function creator()
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    /**
     * Get the employee who last updated this language
     */
    public function updater()
    {
        return $this->belongsTo(User::class, 'updated_by');
    }

    /**
     * Get the employee who deleted this language
     */
    public function deleter()
    {
        return $this->belongsTo(User::class, 'deleted_by');
    }
}
