<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class CitizenshipCountrySetting extends Model
{
    protected $fillable = [
        'country_code',
        'individual_id_enabled',
        'individual_id_required',
        'company_id_enabled',
        'company_id_required',
        'document_upload_enabled',
        'document_upload_required',
        'api_verification_enabled',
        'verification_module',
        'api_provider',
        'api_provider_config',
        'field_settings',
    ];

    protected $casts = [
        'individual_id_enabled' => 'boolean',
        'individual_id_required' => 'boolean',
        'company_id_enabled' => 'boolean',
        'company_id_required' => 'boolean',
        'document_upload_enabled' => 'boolean',
        'document_upload_required' => 'boolean',
        'api_verification_enabled' => 'boolean',
        'field_settings' => 'array',
        'api_provider_config' => 'array',
    ];

    /**
     * Check if a specific field is enabled.
     */
    public function isFieldEnabled(string $fieldKey): bool
    {
        return (bool) ($this->field_settings[$fieldKey]['enabled'] ?? false);
    }

    /**
     * Check if a specific field is required.
     */
    public function isFieldRequired(string $fieldKey): bool
    {
        return (bool) ($this->field_settings[$fieldKey]['required'] ?? false);
    }

    public function country()
    {
        return $this->belongsTo(Country::class, 'country_code', 'iso2');
    }
}
