<?php
$roulette = new \Plugin\NexoraRoulette\NexoraRoulette();
$roulette->ensureSchema();
$settings = $roulette->settings();
$credits = $roulette->creditConfigs();
$items = $roulette->itemshopItems();
$currentPrizes = $roulette->getPrizes(false);
$currentExchange = $roulette->getExchangeRewards(false);
$realm = $roulette->getRealm();
$realmLabel = $roulette->getRealmLabel();

$creditById = array();
foreach($credits as $cfg) $creditById[(int)$cfg['config_id']] = $cfg;
$itemById = array();
foreach($items as $item) $itemById[(int)$item['id']] = $item;

$existingItemByRarity = array('rare'=>0,'epic'=>0,'legendary'=>0);
foreach($currentPrizes as $p) {
    $rarity = (string)($p['rarity'] ?? '');
    if(($p['prize_type'] ?? '') !== 'itemshop' || !isset($existingItemByRarity[$rarity])) continue;
    if($existingItemByRarity[$rarity] > 0) continue;
    if((int)($p['item_id'] ?? 0) > 0) $existingItemByRarity[$rarity] = (int)$p['item_id'];
}

$profiles = array(
    'seasonal' => array(
        'label' => 'Seasonal Controlado',
        'description' => 'Retorno líquido contenido, progresión visible y premios de Arsenal con stock diario estricto.',
        'spin_cost' => 500,
        'pity_threshold' => 20,
        'pity_min_rarity' => 'rare',
        'progression' => array(
            'base_fragments_per_spin'=>1,
            'fragment_bonus_common'=>0,
            'fragment_bonus_uncommon'=>0,
            'fragment_bonus_rare'=>1,
            'fragment_bonus_epic'=>3,
            'fragment_bonus_legendary'=>8,
            'milestones'=>array(
                array(10,5,0),
                array(25,10,0),
                array(50,20,1),
                array(100,40,1),
            ),
        ),
        'prizes' => array(
            array('Retorno NXR · 100 WC','Recupera una parte del costo del giro.','credits','common',3000,100,0,0,0,0,10),
            array('Retorno NXR · 250 WC','Un retorno superior sin devolver el costo completo.','credits','common',1800,250,0,0,0,0,20),
            array('Reentrada NXR · +1 Giro','Obtienes una nueva oportunidad sin consumir saldo.','free_spins','uncommon',800,1,0,0,0,4,30),
            array('Carga de Talismán · 2 Fragmentos','Progreso directo para tu reserva de Fragmentos NXR.','fragments','uncommon',2000,2,0,0,0,0,40),
            array('Núcleo de Talismán · 5 Fragmentos','Una carga superior de progreso para el catálogo de canje.','fragments','rare',1500,5,0,0,0,0,50),
            array('Arsenal Raro','Premio de Arsenal con utilidad real y disponibilidad controlada.','itemshop','rare',800,0,0,0,10,1,60),
            array('Reliquia Épica','Premio de alto valor con aparición excepcional.','itemshop','epic',90,0,0,0,2,1,70),
            array('Legado Nexora','Premio de prestigio de campaña con disponibilidad extremadamente limitada.','itemshop','legendary',10,0,0,0,1,1,80),
        ),
        'exchange' => array(
            array('Reentrada NXR','Canjea progreso por una oportunidad adicional.','free_spins',50,1,0,0,0,0,10),
            array('Triple Giro','Convierte 135 Fragmentos NXR en 3 giros adicionales.','free_spins',135,3,0,0,0,0,20),
            array('Arsenal Raro','Canje controlado por un premio raro de Arsenal.','itemshop',300,0,0,0,30,2,30),
            array('Reliquia Épica','Canje de alto valor con stock global limitado.','itemshop',550,0,0,0,12,1,40),
            array('Legado Nexora','Canje de prestigio con stock de campaña extremadamente reducido.','itemshop',900,0,0,0,3,1,50),
        ),
    ),
    'legacy' => array(
        'label' => 'Legado Prestigio',
        'description' => 'Más retorno y más presencia de Arsenal, manteniendo límites sobre Épicos y Legendarios.',
        'spin_cost' => 500,
        'pity_threshold' => 20,
        'pity_min_rarity' => 'rare',
        'progression' => array(
            'base_fragments_per_spin'=>1,
            'fragment_bonus_common'=>0,
            'fragment_bonus_uncommon'=>0,
            'fragment_bonus_rare'=>1,
            'fragment_bonus_epic'=>3,
            'fragment_bonus_legendary'=>8,
            'milestones'=>array(
                array(10,8,0),
                array(25,15,0),
                array(50,30,1),
                array(100,60,2),
            ),
        ),
        'prizes' => array(
            array('Retorno NXR · 150 WC','Retorno directo pensado para una economía de Legado más madura.','credits','common',2600,150,0,0,0,0,10),
            array('Retorno NXR · 300 WC','Retorno superior sin convertir la ruleta en una fuente neta de moneda.','credits','common',1700,300,0,0,0,0,20),
            array('Reentrada NXR · +1 Giro','Obtienes una nueva oportunidad sin consumir saldo.','free_spins','uncommon',1000,1,0,0,0,5,30),
            array('Carga de Talismán · 2 Fragmentos','Progreso directo para tu reserva de Fragmentos NXR.','fragments','uncommon',1900,2,0,0,0,0,40),
            array('Núcleo de Talismán · 5 Fragmentos','Una carga superior de progreso para el catálogo de canje.','fragments','rare',1400,5,0,0,0,0,50),
            array('Arsenal Raro','Premio de Arsenal con mayor presencia dentro del pool de Legado.','itemshop','rare',1100,0,0,0,20,2,60),
            array('Reliquia Épica','Premio de alto valor reservado para momentos poco frecuentes.','itemshop','epic',250,0,0,0,4,1,70),
            array('Legado Nexora','Premio de prestigio con presencia real, pero stock estricto.','itemshop','legendary',50,0,0,0,1,1,80),
        ),
        'exchange' => array(
            array('Reentrada NXR','Canjea progreso por una oportunidad adicional.','free_spins',45,1,0,0,0,0,10),
            array('Triple Giro','Convierte 120 Fragmentos NXR en 3 giros adicionales.','free_spins',120,3,0,0,0,0,20),
            array('Arsenal Raro','Canje estable para jugadores constantes de Legado.','itemshop',240,0,0,0,50,2,30),
            array('Reliquia Épica','Canje de alto valor con stock global controlado.','itemshop',450,0,0,0,20,1,40),
            array('Legado Nexora','Canje de prestigio para objetivos de largo plazo.','itemshop',700,0,0,0,5,1,50),
        ),
    ),
);

$defaultProfile = $realm === 'seasonal' ? 'seasonal' : 'legacy';
$selectedProfile = isset($_POST['profile']) && isset($profiles[$_POST['profile']]) ? (string)$_POST['profile'] : $defaultProfile;
$walletId = isset($_POST['wallet_config']) ? (int)$_POST['wallet_config'] : (int)$settings['credit_config'];
$spinCostInput = isset($_POST['spin_cost']) ? max(1,(int)$_POST['spin_cost']) : (int)$profiles[$selectedProfile]['spin_cost'];
$rareItemId = isset($_POST['rare_item_id']) ? (int)$_POST['rare_item_id'] : (int)$existingItemByRarity['rare'];
$epicItemId = isset($_POST['epic_item_id']) ? (int)$_POST['epic_item_id'] : (int)$existingItemByRarity['epic'];
$legendaryItemId = isset($_POST['legendary_item_id']) ? (int)$_POST['legendary_item_id'] : (int)$existingItemByRarity['legendary'];

$findByName = function($rows,$name) {
    foreach($rows as $row) if((string)($row['name'] ?? '') === (string)$name) return $row;
    return null;
};

$prizeItemLabel = function($id) use ($itemById) {
    $id=(int)$id;
    if($id<1 || !isset($itemById[$id])) return 'Sin asignar';
    $item=$itemById[$id];
    return '#'.$id.' · '.(string)$item['name'].' · '.(int)$item['item_section'].':'.(int)$item['item_index'];
};

if(isset($_POST['apply_recommended_pool'])) {
    try {
        if(empty($_POST['confirm_apply'])) throw new RuntimeException('Confirma que entiendes que el preset retirará el pool activo actual de este reino.');
        $profileKey=(string)($_POST['profile'] ?? '');
        if(!isset($profiles[$profileKey])) throw new InvalidArgumentException('Preset económico inválido.');
        $profile=$profiles[$profileKey];
        $walletId=(int)($_POST['wallet_config'] ?? 0);
        $spinCost=max(1,(int)($_POST['spin_cost'] ?? 0));
        $rareItemId=(int)($_POST['rare_item_id'] ?? 0);
        $epicItemId=(int)($_POST['epic_item_id'] ?? 0);
        $legendaryItemId=(int)($_POST['legendary_item_id'] ?? 0);
        $replaceExchange=!empty($_POST['replace_exchange']);

        if($walletId<1 || !isset($creditById[$walletId])) throw new RuntimeException('Selecciona la configuración de WCoin/moneda que usará el pool.');
        foreach(array('Raro'=>$rareItemId,'Épico'=>$epicItemId,'Legendario'=>$legendaryItemId) as $label=>$itemId) {
            if($itemId<1 || !isset($itemById[$itemId])) throw new RuntimeException('Selecciona un ítem válido para el slot '.$label.'.');
        }
        if(count(array_unique(array($rareItemId,$epicItemId,$legendaryItemId)))!==3) throw new RuntimeException('Usa tres ítems distintos para Raro, Épico y Legendario.');
        $configPath=\Plugin\NexoraRoulette\NexoraRoulette::configPath($realm);
        if(!is_file($configPath) || !is_writable($configPath)) throw new RuntimeException('La configuración del reino no tiene permiso de escritura.');

        $mappedItems=array('rare'=>$rareItemId,'epic'=>$epicItemId,'legendary'=>$legendaryItemId);
        $beforeActive=0;
        foreach($currentPrizes as $p) if((int)$p['active']===1) { $beforeActive++; $roulette->retirePrize((int)$p['id']); }

        $savedPrizeIds=array();
        $freshPrizes=$roulette->getPrizes(false);
        foreach($profile['prizes'] as $row) {
            list($name,$description,$type,$rarity,$weight,$amount,$creditConfig,$itemId,$dailyGlobal,$dailyAccount,$sortOrder)=$row;
            if($type==='credits') $creditConfig=$walletId;
            if($type==='itemshop') $itemId=$mappedItems[$rarity];
            $existing=$findByName($freshPrizes,$name);
            $savedPrizeIds[]=$roulette->savePrize(array(
                'id'=>is_array($existing)?(int)$existing['id']:0,
                'name'=>$name,
                'description'=>$description,
                'prize_type'=>$type,
                'rarity'=>$rarity,
                'weight'=>$weight,
                'amount'=>$amount,
                'credit_config_id'=>$creditConfig,
                'item_id'=>$itemId,
                'daily_global_limit'=>$dailyGlobal,
                'daily_account_limit'=>$dailyAccount,
                'active'=>1,
                'sort_order'=>$sortOrder,
            ));
            $freshPrizes=$roulette->getPrizes(false);
        }

        $roulette->saveSettings(array(
            'enabled'=>!empty($settings['enabled'])?1:0,
            'title'=>(string)$settings['title'],
            'credit_config'=>$walletId,
            'spin_cost'=>$spinCost,
            'cooldown_seconds'=>(int)$settings['cooldown_seconds'],
            'daily_spin_limit'=>(int)$settings['daily_spin_limit'],
            'show_odds'=>!empty($settings['show_odds'])?1:0,
            'show_recent_winners'=>!empty($settings['show_recent_winners'])?1:0,
            'pity_enabled'=>1,
            'pity_threshold'=>(int)$profile['pity_threshold'],
            'pity_min_rarity'=>(string)$profile['pity_min_rarity'],
        ));

        $prog=$profile['progression'];
        $progressInput=array(
            'progression_enabled'=>1,
            'show_progress'=>1,
            'base_fragments_per_spin'=>(int)$prog['base_fragments_per_spin'],
            'fragment_bonus_common'=>(int)$prog['fragment_bonus_common'],
            'fragment_bonus_uncommon'=>(int)$prog['fragment_bonus_uncommon'],
            'fragment_bonus_rare'=>(int)$prog['fragment_bonus_rare'],
            'fragment_bonus_epic'=>(int)$prog['fragment_bonus_epic'],
            'fragment_bonus_legendary'=>(int)$prog['fragment_bonus_legendary'],
        );
        foreach($prog['milestones'] as $idx=>$milestone) {
            $n=$idx+1;
            $progressInput['milestone_'.$n.'_spins']=(int)$milestone[0];
            $progressInput['milestone_'.$n.'_fragments']=(int)$milestone[1];
            $progressInput['milestone_'.$n.'_free_spins']=(int)$milestone[2];
        }
        $roulette->saveProgression($progressInput);

        if($replaceExchange) {
            $existingExchange=$roulette->getExchangeRewards(false);
            $preservedImages=array();
            foreach($existingExchange as $reward) {
                if(trim((string)($reward['image_file'] ?? ''))!=='') $preservedImages[(string)$reward['name']]=(string)$reward['image_file'];
                if((int)$reward['active']===1) $roulette->retireExchangeReward((int)$reward['id']);
            }
            $freshExchange=$roulette->getExchangeRewards(false);
            foreach($profile['exchange'] as $row) {
                list($name,$description,$type,$cost,$amount,$creditConfig,$itemId,$globalLimit,$accountLimit,$sortOrder)=$row;
                if($type==='itemshop') {
                    if(stripos($name,'Raro')!==false) $itemId=$rareItemId;
                    elseif(stripos($name,'Épica')!==false || stripos($name,'Épico')!==false) $itemId=$epicItemId;
                    else $itemId=$legendaryItemId;
                }
                $existing=$findByName($freshExchange,$name);
                $roulette->saveExchangeReward(array(
                    'id'=>is_array($existing)?(int)$existing['id']:0,
                    'name'=>$name,
                    'description'=>$description,
                    'reward_type'=>$type,
                    'fragment_cost'=>$cost,
                    'amount'=>$amount,
                    'credit_config_id'=>$creditConfig,
                    'item_id'=>$itemId,
                    'image_file'=>isset($preservedImages[$name])?$preservedImages[$name]:(is_array($existing)?(string)($existing['image_file']??''):''),
                    'global_limit'=>$globalLimit,
                    'account_limit'=>$accountLimit,
                    'active'=>1,
                    'sort_order'=>$sortOrder,
                ));
                $freshExchange=$roulette->getExchangeRewards(false);
            }
        }

        if(class_exists('NexoraAudit')) {
            \NexoraAudit::log('roulette.recommended_pool_apply','roulette',$realm,null,array(
                'profile'=>$profileKey,
                'spin_cost'=>$spinCost,
                'wallet_config'=>$walletId,
                'rare_item_id'=>$rareItemId,
                'epic_item_id'=>$epicItemId,
                'legendary_item_id'=>$legendaryItemId,
                'replace_exchange'=>$replaceExchange?1:0,
                'retired_active_prizes'=>$beforeActive,
                'new_prize_ids'=>$savedPrizeIds,
            ),$realm);
        }
        message('success','Preset '.$profile['label'].' aplicado en '.$realmLabel.'. El pool anterior quedó retirado y el historial fue conservado.');
        $settings=$roulette->settings();
        $currentPrizes=$roulette->getPrizes(false);
        $currentExchange=$roulette->getExchangeRewards(false);
        $selectedProfile=$profileKey;
    } catch(Throwable $e) {
        message('error',$e->getMessage());
    }
}

$profile=$profiles[$selectedProfile];
$totalWeight=0; $directWalletEv=0.0; $freeSpinEv=0.0; $fragmentPrizeEv=0.0;
foreach($profile['prizes'] as $row) {
    $weight=(int)$row[4]; $totalWeight+=$weight;
}
foreach($profile['prizes'] as $row) {
    $prob=$totalWeight>0?((int)$row[4]/$totalWeight):0;
    if($row[2]==='credits') $directWalletEv+=$prob*(int)$row[5];
    if($row[2]==='free_spins') $freeSpinEv+=$prob*(int)$row[5];
    if($row[2]==='fragments') $fragmentPrizeEv+=$prob*(int)$row[5];
}
$liquidEv=$directWalletEv+($freeSpinEv*$spinCostInput);
$liquidRatio=$spinCostInput>0?($liquidEv/$spinCostInput)*100:0;
?>
<h1 class="page-header">Presets de Premios <small><?php echo htmlspecialchars($realmLabel,ENT_QUOTES,'UTF-8'); ?></small></h1>
<div class="alert alert-info"><strong>Objetivo:</strong> aplicar una economía provocativa para el jugador sin convertir la ruleta en una fuente neta de WCoin. El preset publica probabilidades reales, mantiene segmentos visuales simétricos y cambia la protección de constancia a <strong>Raro o superior</strong>.</div>

<div class="row">
    <?php foreach($profiles as $key=>$p){ ?>
    <div class="col-md-6">
        <div class="panel <?php echo $key===$selectedProfile?'panel-primary':'panel-default'; ?>">
            <div class="panel-heading"><strong><?php echo htmlspecialchars($p['label'],ENT_QUOTES,'UTF-8'); ?></strong></div>
            <div class="panel-body">
                <p><?php echo htmlspecialchars($p['description'],ENT_QUOTES,'UTF-8'); ?></p>
                <p style="margin-bottom:0"><strong>Pity:</strong> <?php echo (int)$p['pity_threshold']; ?> giros · Raro o superior<br><strong>Pool:</strong> 8 segmentos visuales iguales · 10.000 puntos de peso</p>
            </div>
        </div>
    </div>
    <?php } ?>
</div>

<div class="panel panel-warning">
    <div class="panel-heading"><strong>Economía estimada del preset seleccionado</strong></div>
    <div class="panel-body">
        <div class="row">
            <div class="col-sm-3"><small>Retorno directo de moneda</small><h3 style="margin:5px 0"><?php echo number_format($directWalletEv,1); ?></h3></div>
            <div class="col-sm-3"><small>Giros gratis esperados</small><h3 style="margin:5px 0"><?php echo number_format($freeSpinEv,3); ?></h3></div>
            <div class="col-sm-3"><small>Fragmentos directos esperados</small><h3 style="margin:5px 0"><?php echo number_format($fragmentPrizeEv,2); ?></h3></div>
            <div class="col-sm-3"><small>Retorno líquido base</small><h3 style="margin:5px 0"><?php echo number_format($liquidRatio,1); ?>%</h3></div>
        </div>
        <p class="text-muted" style="margin-bottom:0">El retorno líquido base sólo valora moneda + giros gratis al costo configurado. No monetiza Fragmentos, hitos ni ítems de Arsenal; por eso debes revisar Economía después de aplicar el preset.</p>
    </div>
</div>

<form method="post" onsubmit="return confirm('Esto retirará el pool activo actual de este reino y aplicará el preset seleccionado. ¿Continuar?');">
<div class="panel panel-default"><div class="panel-heading"><strong>Aplicar preset al reino operativo</strong></div><div class="panel-body">
    <div class="row">
        <div class="col-md-4"><div class="form-group"><label>Perfil económico</label><select class="form-control" name="profile" onchange="this.form.submit()"><option value="seasonal" <?php echo $selectedProfile==='seasonal'?'selected':''; ?>>Seasonal Controlado</option><option value="legacy" <?php echo $selectedProfile==='legacy'?'selected':''; ?>>Legado Prestigio</option></select><span class="help-block">Cambiar el selector sólo refresca la vista; no aplica cambios hasta usar el botón final.</span></div></div>
        <div class="col-md-4"><div class="form-group"><label>Moneda del giro / retornos</label><select class="form-control" name="wallet_config" required><option value="0">— Seleccionar —</option><?php foreach($credits as $cfg){ ?><option value="<?php echo (int)$cfg['config_id']; ?>" <?php echo $walletId===(int)$cfg['config_id']?'selected':''; ?>>#<?php echo (int)$cfg['config_id']; ?> · <?php echo htmlspecialchars($cfg['config_title'],ENT_QUOTES,'UTF-8'); ?></option><?php } ?></select></div></div>
        <div class="col-md-4"><div class="form-group"><label>Costo por giro</label><div class="input-group"><input class="form-control" type="number" min="1" name="spin_cost" value="<?php echo (int)$spinCostInput; ?>"><span class="input-group-addon">WC</span></div><span class="help-block">El preset fue balanceado alrededor de 500.</span></div></div>
    </div>
    <hr>
    <p><strong>Mapeo de premios Arsenal.</strong> Estos tres ítems son los chase prizes. El sistema no inventa IDs ni cambia sus propiedades: sólo referencia productos existentes de Arsenal.</p>
    <div class="row">
        <?php foreach(array('rare_item_id'=>array('Raro',$rareItemId),'epic_item_id'=>array('Épico',$epicItemId),'legendary_item_id'=>array('Legendario',$legendaryItemId)) as $field=>$meta){ ?>
        <div class="col-md-4"><div class="form-group"><label><?php echo $meta[0]; ?></label><select class="form-control" name="<?php echo $field; ?>" required><option value="0">— Seleccionar Arsenal —</option><?php foreach($items as $item){ $label='#'.(int)$item['id'].' · '.(string)$item['name'].' · '.(int)$item['item_section'].':'.(int)$item['item_index']; ?><option value="<?php echo (int)$item['id']; ?>" <?php echo (int)$meta[1]===(int)$item['id']?'selected':''; ?>><?php echo htmlspecialchars($label,ENT_QUOTES,'UTF-8'); ?></option><?php } ?></select></div></div>
        <?php } ?>
    </div>
    <div class="checkbox"><label><input type="checkbox" name="replace_exchange" value="1" checked> Reemplazar también el catálogo activo de Fragmentos por el catálogo recomendado</label></div>
    <div class="checkbox"><label><input type="checkbox" name="confirm_apply" value="1" required> Entiendo que los premios activos actuales se retirarán de este reino; su historial no se elimina.</label></div>
    <button type="submit" class="btn btn-danger btn-lg" name="apply_recommended_pool" value="1"><i class="fa fa-magic"></i> Aplicar pool recomendado</button>
</div></div>
</form>

<div class="panel panel-default"><div class="panel-heading"><strong>Pool que se aplicará</strong></div><div class="table-responsive"><table class="table table-striped table-hover" style="margin:0"><thead><tr><th>Premio</th><th>Tipo</th><th>Rareza</th><th>Peso</th><th>Probabilidad</th><th>Límite diario</th></tr></thead><tbody>
<?php foreach($profile['prizes'] as $row){ $prob=$totalWeight>0?((int)$row[4]/$totalWeight)*100:0; ?><tr><td><strong><?php echo htmlspecialchars($row[0],ENT_QUOTES,'UTF-8'); ?></strong><br><small><?php echo htmlspecialchars($row[1],ENT_QUOTES,'UTF-8'); ?></small></td><td><?php echo htmlspecialchars(\Plugin\NexoraRoulette\NexoraRoulette::prizeTypeLabels()[$row[2]]??$row[2],ENT_QUOTES,'UTF-8'); ?></td><td><?php echo htmlspecialchars(\Plugin\NexoraRoulette\NexoraRoulette::rarityLabels()[$row[3]]??$row[3],ENT_QUOTES,'UTF-8'); ?></td><td><?php echo number_format((int)$row[4]); ?></td><td><strong><?php echo number_format($prob,2); ?>%</strong></td><td><small>Global: <?php echo (int)$row[8]?:'∞'; ?><br>Cuenta: <?php echo (int)$row[9]?:'∞'; ?></small></td></tr><?php } ?>
</tbody></table></div></div>

<div class="panel panel-default"><div class="panel-heading"><strong>Catálogo de Fragmentos recomendado</strong></div><div class="table-responsive"><table class="table table-striped" style="margin:0"><thead><tr><th>Canje</th><th>Costo</th><th>Entrega</th><th>Stock global</th><th>Límite por cuenta</th></tr></thead><tbody>
<?php foreach($profile['exchange'] as $row){ ?><tr><td><strong><?php echo htmlspecialchars($row[0],ENT_QUOTES,'UTF-8'); ?></strong><br><small><?php echo htmlspecialchars($row[1],ENT_QUOTES,'UTF-8'); ?></small></td><td><?php echo number_format((int)$row[3]); ?> Fragmentos</td><td><?php if($row[2]==='free_spins') echo '+'.(int)$row[4].' giro'.((int)$row[4]===1?'':'s'); else echo 'Arsenal'; ?></td><td><?php echo (int)$row[7]?:'Abierto'; ?></td><td><?php echo (int)$row[8]?:'Sin límite'; ?></td></tr><?php } ?>
</tbody></table></div></div>

<div class="alert alert-warning"><strong>Después de aplicar:</strong> entra en <a href="<?php echo admincp_base('nexoraroulette&page=economy'); ?>">Economía</a> y ejecuta primero 10.000 giros, luego 100.000. Los ítems de Arsenal no tienen una equivalencia automática en WCoin, así que el simulador debe complementarse con tu criterio de valor real del servidor.</div>
