// File: @openzeppelin/contracts/access/Ownable.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

// File: @openzeppelin/contracts/token/ERC20/IERC20.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
}

// File: @openzeppelin/contracts/utils/Context.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}

// File: @openzeppelin/contracts/utils/Counters.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)

pragma solidity ^0.8.0;

/**
 * @title Counters
 * @author Matt Condon (@shrugs)
 * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
 * of elements in a mapping, issuing ERC721 ids, or counting request ids.
 *
 * Include with `using Counters for Counters.Counter;`
 */
library Counters {
    struct Counter {
        // This variable should never be directly accessed by users of the library: interactions must be restricted to
        // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
        // this feature: see https://github.com/ethereum/solidity/issues/4637
        uint256 _value; // default: 0
    }

    function current(Counter storage counter) internal view returns (uint256) {
        return counter._value;
    }

    function increment(Counter storage counter) internal {
        unchecked {
            counter._value += 1;
        }
    }

    function decrement(Counter storage counter) internal {
        uint256 value = counter._value;
        require(value > 0, "Counter: decrement overflow");
        unchecked {
            counter._value = value - 1;
        }
    }

    function reset(Counter storage counter) internal {
        counter._value = 0;
    }
}

// File: @uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol



pragma solidity >=0.5.0;

interface IUniswapV2Factory {
    event PairCreated(address indexed token0, address indexed token1, address pair, uint);

    function feeTo() external view returns (address);
    function feeToSetter() external view returns (address);

    function getPair(address tokenA, address tokenB) external view returns (address pair);
    function allPairs(uint) external view returns (address pair);
    function allPairsLength() external view returns (uint);

    function createPair(address tokenA, address tokenB) external returns (address pair);

    function setFeeTo(address) external;
    function setFeeToSetter(address) external;
}

// File: @uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol



pragma solidity >=0.5.0;

interface IUniswapV2Pair {
    event Approval(address indexed owner, address indexed spender, uint value);
    event Transfer(address indexed from, address indexed to, uint value);

    function name() external pure returns (string memory);
    function symbol() external pure returns (string memory);
    function decimals() external pure returns (uint8);
    function totalSupply() external view returns (uint);
    function balanceOf(address owner) external view returns (uint);
    function allowance(address owner, address spender) external view returns (uint);

    function approve(address spender, uint value) external returns (bool);
    function transfer(address to, uint value) external returns (bool);
    function transferFrom(address from, address to, uint value) external returns (bool);

    function DOMAIN_SEPARATOR() external view returns (bytes32);
    function PERMIT_TYPEHASH() external pure returns (bytes32);
    function nonces(address owner) external view returns (uint);

    function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;

    event Mint(address indexed sender, uint amount0, uint amount1);
    event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
    event Swap(
        address indexed sender,
        uint amount0In,
        uint amount1In,
        uint amount0Out,
        uint amount1Out,
        address indexed to
    );
    event Sync(uint112 reserve0, uint112 reserve1);

    function MINIMUM_LIQUIDITY() external pure returns (uint);
    function factory() external view returns (address);
    function token0() external view returns (address);
    function token1() external view returns (address);
    function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
    function price0CumulativeLast() external view returns (uint);
    function price1CumulativeLast() external view returns (uint);
    function kLast() external view returns (uint);

    function mint(address to) external returns (uint liquidity);
    function burn(address to) external returns (uint amount0, uint amount1);
    function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
    function skim(address to) external;
    function sync() external;

    function initialize(address, address) external;
}

// File: @uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router01.sol



pragma solidity >=0.6.2;

interface IUniswapV2Router01 {
    function factory() external pure returns (address);
    function WETH() external pure returns (address);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB, uint liquidity);
    function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountToken, uint amountETH);
    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountToken, uint amountETH);
    function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);
    function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);

    function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
    function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
    function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}

// File: @uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol



pragma solidity >=0.6.2;

import './IUniswapV2Router01.sol';

interface IUniswapV2Router02 is IUniswapV2Router01 {
    function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountETH);
    function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountETH);

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable;
    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
}

// File: contracts/BlokcCore/BlokcCore.sol



// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {Counters} from "@openzeppelin/contracts/utils/Counters.sol";

import {IUniswapV2Router02} from "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
import {IUniswapV2Pair} from "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol";
import {IUniswapV2Factory} from "@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol";


import {GardenerBlokc} from "./GardenerBlokc.sol";
import {GardenBlokc} from "./GardenBlokc.sol";

// solhint-disable-next-line no-empty-blocks
contract BlokcCore is GardenerBlokc, GardenBlokc {


}

// File: contracts/BlokcCore/GardenBlokc.sol



// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;

// Import Uniswap interfaces directly
import {IUniswapV2Router02} from "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
import {IUniswapV2Pair} from "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol";
import {IUniswapV2Factory} from "@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol";

// import "forge-std/console.sol";



import {IGardenBlokc, Garden, TokenAmount} from "./interfaces/IGardenBlokc.sol";
import {Gardener, GardenersGardenData, GardenerStrategy} from "./interfaces/IGardenerBlokc.sol";
import {GardenerBlokc} from "./GardenerBlokc.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {Counters} from "@openzeppelin/contracts/utils/Counters.sol";


abstract contract GardenBlokc is GardenerBlokc, IGardenBlokc {
    mapping(address => Garden[]) public gardens;

    function getGardensByAddress(
        address _userAddress
    ) external view returns (Garden[] memory) {
        return gardens[_userAddress];
    }



function createGarden(
    uint256 _gardenerId,
    uint256 _amount,
    string memory _gardenName
  
) external {
    require(isGardenerRegistered[idToGardener[_gardenerId].gardenerAddress], "Gardener is not registered");
    require(_amount > 0, "Amount must be greater than 0");

    uint256 gardenId = gardens[msg.sender].length;
    _assignGardener(_gardenerId, gardenId, msg.sender);

    Gardener storage gardener = idToGardener[_gardenerId];
    GardenerStrategy memory selectedStrategy = selectStrategy(gardener, _amount);

    Garden storage garden = gardens[msg.sender].push();
    garden.id = gardenId;
    garden.gardenName = _gardenName;
    garden.owner = msg.sender; // User is the owner of the garden
    garden.gardenerId = _gardenerId;    
    garden.gardenerAddress = idToGardener[_gardenerId].gardenerAddress;
    garden.gardenerUsername = idToGardener[_gardenerId].username;
    // garden.composition = selectedStrategy.token;
    garden.createdAt = block.timestamp;
        TokenAmount storage tokenAmount = garden.composition.push();
        tokenAmount.token = selectedStrategy.cryptos;
        tokenAmount.amount = selectedStrategy.percentages;

     
    // address usdtToken = 0xda06447AD1dEA10D07c1c2E6C7853d3cbb2bC35e;  // USDT token address
    // address uniswapRouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; // Uniswap router address
    // address wethToken = IUniswapV2Router02(uniswapRouter).WETH();

    // Swap USDT to ETH first

    // Try to swap USDT to ETH using Uniswap
    // try IERC20(usdtToken).approve(uniswapRouter, _amount) and IUniswapV2Router02(uniswapRouter).swapExactTokensForETH(
    //     _amount,
    //     0,
    //     new address[](0),
    //     address(this),
    //     block.timestamp
    // ) {
    //     // Do nothing on success
    // } catch Error(string memory reason) {
    //     // Revert the transaction if there is an error
    //     revert(reason);
    // }

    // Perform token swaps based on the strategy
    // for (uint256 i = 0; i < selectedStrategy.cryptos.length; i++) {
    //     address crypto = selectedStrategy.cryptos[i];
    //     uint8 percentage = selectedStrategy.percentages[i];

    //     uint256 allocationAmount = (_amount * percentage) / 100;

        // IUniswapV2Pair pair = IUniswapV2Pair(IUniswapV2Factory(IUniswapV2Router02(uniswapRouter).factory()).getPair(wethToken, crypto));

        // require(address(pair) != address(0), "Pair not found");

        // Try to swap ETH to 'crypto' and transfer tokens to user
        // try IERC20(wethToken).approve(uniswapRouter, allocationAmount) and IUniswapV2Router02(uniswapRouter).swapExactETHForTokens{value: allocationAmount}(
        //     0,
        //     new address[](0),
        //     msg.sender, // Transfer tokens to the user
        //     block.timestamp
        // ) {
        //     // Do nothing on success
        // } catch Error(string memory reason) {
        //     // Revert the transaction if there is an error
        //     revert(reason);
        // }
    }


function selectStrategy(Gardener storage gardener, uint256 _amount) internal view returns (GardenerStrategy memory) {
    for (uint256 i = 0; i < gardener.strategies.length; i++) {
        GardenerStrategy memory strategy = gardener.strategies[i];
        if (_amount >= strategy.minAmount && _amount <= strategy.maxAmount) {
            return strategy;
        }
    }
    
    // Return a default strategy or revert if none found
    revert("No matching strategy found");
}


    function _assignGardener(
        uint256 _gardenerId,
        uint256 _gardenId,
        address _userAddress
    ) internal {
        Gardener storage gardener = idToGardener[_gardenerId];
        require(
            isGardenerRegistered[gardener.gardenerAddress],
            "Gardener is not registered"
        );
        GardenersGardenData[] storage gardenersGardens = gardener.gardens;
        for (uint256 i = 0; i < gardenersGardens.length; i++) {
            require(
                !(gardenersGardens[i].id == _gardenId &&
                    gardenersGardens[i].userAddress == _userAddress),
                "Garden is already assigned to gardener"
            );
        }
        GardenersGardenData storage newGarden = gardenersGardens.push();
        newGarden.id = _gardenId;
        newGarden.userAddress = _userAddress;
    }

    function changeGardener(uint256 _gardenerId, uint256 _gardenId) external {
        _assignGardener(_gardenerId, _gardenId, msg.sender);
        Garden storage garden = gardens[msg.sender][_gardenId];
        garden.gardenerId = _gardenerId;
        garden.gardenerAddress = idToGardener[_gardenerId].gardenerAddress;
        garden.gardenerUsername = idToGardener[_gardenerId].username;
    }

    function changeGardenComposition(
        uint256 _idGarden,
        address _userAddress,
        TokenAmount[] memory composition
    ) external {
        Garden storage garden = gardens[_userAddress][_idGarden];
        delete garden.composition;
        for (uint256 i = 0; i < composition.length; i++) {
            garden.composition.push(composition[i]);
        }
    }
}

// File: contracts/BlokcCore/GardenerBlokc.sol



// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;

import {IGardenerBlokc, Gardener, GardenersGardenData, GardenerStrategy} from "./interfaces/IGardenerBlokc.sol";
import {Counters} from "@openzeppelin/contracts/utils/Counters.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

abstract contract GardenerBlokc is Ownable, IGardenerBlokc {
    using Counters for Counters.Counter;
    Counters.Counter private idGardeners;

    mapping(uint256 => Gardener) internal idToGardener;
    mapping(address => uint256) public gardenerAddressToId;
    mapping(address => bool) public isGardenerRegistered;
    mapping(string => bool) public isStrategyCreated;

    


    event StrategyCreated(address indexed gardener, uint256 strategyIndex);

    function registerGardener(
        string memory _username,
        address _addressGardener
    ) external {
        require(
            !isGardenerRegistered[_addressGardener],
            "Gardener is already registered"
        );
        uint256 newId = idGardeners.current();
        idGardeners.increment();
        Gardener storage gardener = idToGardener[newId];
        gardener.id = newId;
        gardener.gardenerAddress = _addressGardener;
        gardener.username = _username;
        isGardenerRegistered[_addressGardener] = true;
        gardenerAddressToId[_addressGardener] = newId;
    }

      function createStrategy(
        uint256 _minAmount,
        uint256 _maxAmount,
        string memory _strategyName,
        address[] memory _cryptos,
        uint8[] memory _percentages
    ) external {
        require(isGardenerRegistered[msg.sender], "Gardener is not registered");
        require(_minAmount > 0 && _maxAmount > _minAmount, "Invalid min/max amounts");
        require(_cryptos.length == _percentages.length, "Arrays must have equal length");
        
        uint8 totalPercentage;

        for (uint256 i = 0; i < _cryptos.length; i++) {
            totalPercentage += _percentages[i];
        }

        require(totalPercentage == 100, "Total percentage must be 100");

        Gardener storage gardener = idToGardener[gardenerAddressToId[msg.sender]];
        gardener.strategies.push(
            GardenerStrategy({
                minAmount: _minAmount,
                maxAmount: _maxAmount,
                strategyName : _strategyName,
                cryptos: _cryptos,
                percentages: _percentages
            })
        );
    }




    function viewAllStrategiesForGardener(address _gardenerAddress)
        external
        view
        returns (GardenerStrategy[] memory)
    {
        require(isGardenerRegistered[_gardenerAddress], "Gardener is not registered");
        uint256 idGardener = gardenerAddressToId[_gardenerAddress];
        Gardener storage gardener = idToGardener[idGardener];
        return gardener.strategies;
    }

    
   
    function getGardener(
        uint256 _gardenerId
    ) external view returns (Gardener memory) {
        require(_gardenerId < idGardeners.current(), "Gardener doesn't exist");
        Gardener memory gardener = idToGardener[_gardenerId];
        return gardener;
    }

    function getAllGardeners() external view returns (Gardener[] memory) {
        uint256 totalGardeners = idGardeners.current();
        Gardener[] memory allGardeners = new Gardener[](totalGardeners);
        for (uint256 i = 0; i < totalGardeners; i++) {
            allGardeners[i] = idToGardener[i];
        }
        return allGardeners;
    }


    function getGardensForGardener()
        external
        view
        returns (GardenersGardenData[] memory gardens)
    {
        require(isGardenerRegistered[msg.sender], "Gardener is not registered");
        uint256 idGardener = gardenerAddressToId[msg.sender];
        Gardener memory gardener = idToGardener[idGardener];
        return gardener.gardens;
    }


    function getIdGardener() external view returns (uint256 id) {
        require(isGardenerRegistered[msg.sender], "Gardener is not registered");
        uint256 idGardener = gardenerAddressToId[msg.sender];
        return idGardener;
    }
}

// File: contracts/BlokcCore/interfaces/IGardenBlokc.sol



// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;

struct TokenAmount {
    address[] token;
    uint256[] amount;
   
}

struct Garden {
    uint256 id;
    address owner;
    uint256 gardenerId;
    address gardenerAddress;
    TokenAmount[] composition;
    uint256 createdAt;
    string gardenerUsername;
    string gardenName;
}

interface IGardenBlokc {
    function createGarden(
        uint256 _gardenerId,
        uint256 _amount,
        string memory _gardenName
    ) external;

    function changeGardener(uint256 _gardenerId, uint256 _gardenId) external;

    function getGardensByAddress(
        address _userAddress
    ) external view returns (Garden[] memory);

    function changeGardenComposition(
        uint256 _idGarden,
        address _userAddress,
        TokenAmount[] memory composition
    ) external;
}

// File: contracts/BlokcCore/interfaces/IGardenerBlokc.sol



// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;

struct GardenersGardenData {
    uint256 id;
    address userAddress;
    // string[] cryptos;`
    // uint8[] percentages;
}

struct Gardener {
    uint256 id;
    string username;
    address gardenerAddress;
    GardenersGardenData[] gardens;
    GardenerStrategy[] strategies; 
}

struct GardenerStrategy {
    uint256 minAmount;
    uint256 maxAmount;
    string strategyName;
    address[] cryptos;
    uint8[] percentages;
}
interface IGardenerBlokc {
    function registerGardener(
        string memory _username,
        address _addressGardener
    ) external;

      function createStrategy(
        uint256 _minAmount,
        uint256 _maxAmount,
        string memory _strategyName,
        address[] memory _cryptos,
        uint8[] memory _percentages
    ) external;



    function getGardener(
        uint256 _gardenerId
    ) external view returns (Gardener memory);

    function getAllGardeners() external view returns (Gardener[] memory);

    function getGardensForGardener()
        external
        view
        returns (GardenersGardenData[] memory gardens);

    function getIdGardener() external view returns (uint256 id);
}