public void InsuranceBuy(Character character, Robot robot, ref int currentInsurances, int maxInsurances, int insuranceDays, ref Corporation corporation)
        {
            robot.ED.ThrowIfEqual(Robot.NoobBotEntityDefault, ErrorCodes.DefinitionNotSupported);
            robot.IsSingleAndUnpacked.ThrowIfFalse(ErrorCodes.RobotMustbeSingleAndNonRepacked);

            robot.Initialize(character);
            robot.CheckOwnerCharacterAndCorporationAndThrowIfFailed(character);
            corporation = character.GetCorporation();

            long?corporationEid       = character.CorporationEid;
            var  useCorporationWallet = false;
            var  endDate = DateTime.Now.AddDays(insuranceDays);

            var insurance = _insuranceHelper.GetInsurance(robot.Eid);

            _insuranceHelper.GetConditions(character, robot, insurance, (long)corporationEid, insuranceDays, maxInsurances, currentInsurances, ref endDate, ref useCorporationWallet).ThrowIfError();

            var wallet = character.GetWalletWithAccessCheck(useCorporationWallet, TransactionType.InsuranceFee);

            double insuranceFee, payOut;

            GetInsurancePrice(robot, out insuranceFee, out payOut).ThrowIfError();

            wallet.Balance -= insuranceFee;

            var b = TransactionLogEvent.Builder()
                    .SetCharacter(character)
                    .SetTransactionType(TransactionType.InsuranceFee)
                    .SetCreditBalance(wallet.Balance)
                    .SetCreditChange(-insuranceFee)
                    .SetItem(robot);

            var corpWallet = wallet as CorporationWallet;

            if (corpWallet != null)
            {
                b.SetCorporation(corpWallet.Corporation);
                corporation.LogTransaction(b);
            }
            else
            {
                character.LogTransaction(b);
            }

            if (!useCorporationWallet)
            {
                corporationEid = null;
            }

            InsuranceHelper.AddInsurance(character, robot.Eid, endDate, InsuranceType.robotInsurance, corporationEid, payOut).ThrowIfError();
            character.GetCurrentDockingBase().AddCentralBank(TransactionType.InsuranceFee, insuranceFee);
            currentInsurances++;
        }
        public ErrorCodes InsuranceDelete(Character character, long targetEid)
        {
            //auto clean
            InsuranceHelper.CleanUpInsurances();

            var item = Item.GetOrThrow(targetEid);

            var insurance = _insuranceHelper.GetInsurance(targetEid);

            if (insurance == null)
            {
                return(ErrorCodes.NoError);
            }

            if (insurance.corporationEid != null)
            {
                var corporation = character.GetCorporation();
                var role        = corporation.GetMemberRole(character);

                //ha nem az issuer akarja torolni
                if (insurance.character != character)
                {
                    //akkor torolhetio a CEO, dpCEO
                    if (!role.IsAnyRole(CorporationRole.DeputyCEO, CorporationRole.CEO, CorporationRole.Accountant))
                    {
                        return(ErrorCodes.InsufficientPrivileges);
                    }
                }
            }
            else
            {
                //le lehet torolni ha
                // - nalad van
                // - te kototted

                if (!((item.Owner == character.Eid) || (insurance.character == character)))
                {
                    return(ErrorCodes.AccessDenied);
                }
            }

            _insuranceHelper.DeleteAndInform(insurance, item.Eid);
            return(ErrorCodes.NoError);
        }