<?php

namespace App\Models;

use App\Enums\AccrualFrequency;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;

#[Fillable([
    'min_amount',
    'max_amount',
    'monthly_return',
    'payment_method',
    'payment_address',
    'require_kyc_to_invest',
    'require_kyc_to_withdraw',
    'referral_direct_percent',
    'referral_indirect_percent',
    'referral_direct_earning_limit',
    'referral_indirect_earning_limit',
    'withdrawal_fee_percent',
    'withdrawal_fee_fixed',
    'min_withdrawal_amount',
    'accrual_frequency',
    'accrual_day_of_month',
    'maintenance_mode_enabled',
])]
class InvestmentSetting extends Model
{
    /**
     * Get the default investment settings row.
     */
    public static function current(): self
    {
        return static::query()->firstOrCreate([], [
            'min_amount' => 200,
            'max_amount' => 50000,
            'monthly_return' => 3.5,
            'payment_method' => 'TRC20',
            'payment_address' => 'TUjJn5yk7XvkESScqMqPvThPvvzJASK1BYN',
            'require_kyc_to_invest' => true,
            'require_kyc_to_withdraw' => true,
            'referral_direct_percent' => 7,
            'referral_indirect_percent' => 5,
            'referral_direct_earning_limit' => null,
            'referral_indirect_earning_limit' => null,
            'withdrawal_fee_percent' => 0,
            'withdrawal_fee_fixed' => 0,
            'min_withdrawal_amount' => 50,
            'accrual_frequency' => AccrualFrequency::Monthly->value,
            'accrual_day_of_month' => 30,
            'maintenance_mode_enabled' => false,
        ]);
    }

    /**
     * Get the attributes that should be cast.
     *
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'min_amount' => 'decimal:2',
            'max_amount' => 'decimal:2',
            'monthly_return' => 'decimal:2',
            'require_kyc_to_invest' => 'boolean',
            'require_kyc_to_withdraw' => 'boolean',
            'referral_direct_percent' => 'decimal:4',
            'referral_indirect_percent' => 'decimal:4',
            'referral_direct_earning_limit' => 'decimal:2',
            'referral_indirect_earning_limit' => 'decimal:2',
            'withdrawal_fee_percent' => 'decimal:4',
            'withdrawal_fee_fixed' => 'decimal:2',
            'min_withdrawal_amount' => 'decimal:2',
            'accrual_frequency' => AccrualFrequency::class,
            'accrual_day_of_month' => 'integer',
            'maintenance_mode_enabled' => 'boolean',
        ];
    }
}
