<?php

namespace Shm\ShmAdmin\AdminRPC;

use Shm\Shm;
use Shm\ShmAdmin\AdminPanel;
use Shm\ShmAuth\Auth;
use Shm\ShmDB\mDB;
use Shm\ShmIntegrations\TBankNominal\TBankCollections\TNominalBankDetails;

use Shm\ShmRPC\ShmRPC;
use Shm\ShmSocial\ShmSocials;
use Shm\ShmUtils\I18n;
use Shm\ShmUtils\Response;
use Shm\ShmUtils\ShmManticore;

class AdminRPCTCompanyBankSend
{
    public static function rpc()
    {

        return ShmRPC::lazy(function () {

            return [
                'type' => TNominalBankDetails::structure(),

                'resolve' => function ($root, $args) {



                    Auth::authenticateOrThrow(...AdminPanel::$authStructures);




                    $bankDetails = TNominalBankDetails::structure()->findOne([
                        'owner' => Auth::getAuthID(),
                        'ownerCollection' =>  Auth::getAuthCollection(),
                    ]);
                    if (!$bankDetails) {
                        ShmRPC::error(I18n::get('bank_details_not_found'));
                    }

                    TNominalBankDetails::validateBankDetails($bankDetails);



                    TNominalBankDetails::structure()->updateOne([
                        '_id' => $bankDetails['_id'],
                    ], [
                        '$set' => [
                            'status' => 'pending',
                        ],
                    ]);

                    return TNominalBankDetails::structure()->findOne([
                        '_id' => $bankDetails['_id'],
                    ]);
                }

            ];
        });
    }
}