<?php

namespace App\Models\CSRNow;

use App\Models\PDFSetting;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Country extends Model
{
    use HasFactory, SoftDeletes;

    const ACTIVE = 1;
    const INACTIVE = 0;
    const ARCHIVED = 1;
    const UNARCHIVED = 0;
    protected $guarded = [];
    protected $casts = [
        'is_active' => 'int',
        'deleted_at' => 'custom_datetime:d-m-Y'
    ];

    protected $connection = 'csrnow_db';
    protected $table = 'countries';

    public function pdfSettings()
    {
        return $this->hasMany(PDFSetting::class);
    }

    public function scopeWhereActive(Builder $query)
    {
        return $query->where('is_active', '=', self::ACTIVE);
    }

    public function languages()
    {
        return $this->belongsTo(Language::class, 'language_id');
    }
}
