<?php

namespace App\Models\Tenants;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class BarobillConfig extends Model
{
    use SoftDeletes;

    protected $fillable = [
        'name',
        'environment',
        'cert_key',
        'corp_num',
        'base_url',
        'description',
        'is_active',
    ];

    protected $casts = [
        'is_active' => 'boolean',
    ];

    public static function getActiveTest(): ?self
    {
        return self::where('environment', 'test')->first();
    }

    public static function getActiveProduction(): ?self
    {
        return self::where('environment', 'production')->first();
    }

    public static function getActive(bool $isTestMode = false): ?self
    {
        return $isTestMode ? self::getActiveTest() : self::getActiveProduction();
    }
}
