import click
from . import utils


@click.group()
def main():
    "Simple CLI for oracles to work with Ether dollar"
    pass


@main.command()
@click.option('--ether-price', type=float, help="The ether price in ether dollar")
@click.option('--collateral-ratio', type=float, help="The collateral ratio")
@click.option(
    '--liquidation-duration',
    type=int,
    help="The liquidation duration in minutes")
@click.option(
    '--private-key',
    callback=utils.check_account,
    help='The privat key to sign the transaction')
def vote(ether_price, collateral_ratio, liquidation_duration, private_key):
    "Vote on the variable for setting up Ether Bank"

    assert [ether_price, collateral_ratio, liquidation_duration
            ].count(None) == 2, "You should set one variable per vote"
    if ether_price:
        var_code = 0
        value = int(ether_price * 100)
    elif collateral_ratio:
        var_code = 1
        value = int(collateral_ratio * 1000)
    elif liquidation_duration:
        var_code = 2
        value = liquidation_duration * 60
    func = utils.contracts['oracles'].functions.vote(var_code, value)
    tx_hash = utils.send_transaction(func, 0, private_key)
    return tx_hash


@main.command()
@click.option('--oracle', required=True, help="The oracle's address")
@click.option('--score', type=int, required=True, help="The oracle's score")
@click.option(
    '--private-key',
    callback=utils.check_account,
    help='The privat key to sign the transaction')
def set_score(oracle, score, private_key):
    "Edit oracle's score"

    oracle = utils.w3.toChecksumAddress(oracle)
    func = utils.contracts['oracles'].functions.setScore(oracle, score)
    tx_hash = utils.send_transaction(func, 0, private_key)
    return tx_hash


@main.command()
@click.option(
    '--private-key',
    callback=utils.check_account,
    help='The privat key to sign the transaction')
def finish_recruiting(private_key):
    "Set recruiting as finished"

    func = utils.contracts['oracles'].functions.finishRecruiting()
    tx_hash = utils.send_transaction(func, 0, private_key)
    return tx_hash


if __name__ == '__main__':
    main()

[((36, 49), 'click.group', 'click.group', ([], {}), '()\n', (47, 49), False, 'import click\n'), ((145, 231), 'click.option', 'click.option', (['"""--ether-price"""'], {'type': 'float', 'help': '"""The ether price in ether dollar"""'}), "('--ether-price', type=float, help=\n    'The ether price in ether dollar')\n", (157, 231), False, 'import click\n'), ((228, 303), 'click.option', 'click.option', (['"""--collateral-ratio"""'], {'type': 'float', 'help': '"""The collateral ratio"""'}), "('--collateral-ratio', type=float, help='The collateral ratio')\n", (240, 303), False, 'import click\n'), ((305, 402), 'click.option', 'click.option', (['"""--liquidation-duration"""'], {'type': 'int', 'help': '"""The liquidation duration in minutes"""'}), "('--liquidation-duration', type=int, help=\n    'The liquidation duration in minutes')\n", (317, 402), False, 'import click\n'), ((412, 523), 'click.option', 'click.option', (['"""--private-key"""'], {'callback': 'utils.check_account', 'help': '"""The privat key to sign the transaction"""'}), "('--private-key', callback=utils.check_account, help=\n    'The privat key to sign the transaction')\n", (424, 523), False, 'import click\n'), ((1231, 1299), 'click.option', 'click.option', (['"""--oracle"""'], {'required': '(True)', 'help': '"""The oracle\'s address"""'}), '(\'--oracle\', required=True, help="The oracle\'s address")\n', (1243, 1299), False, 'import click\n'), ((1301, 1376), 'click.option', 'click.option', (['"""--score"""'], {'type': 'int', 'required': '(True)', 'help': '"""The oracle\'s score"""'}), '(\'--score\', type=int, required=True, help="The oracle\'s score")\n', (1313, 1376), False, 'import click\n'), ((1378, 1489), 'click.option', 'click.option', (['"""--private-key"""'], {'callback': 'utils.check_account', 'help': '"""The privat key to sign the transaction"""'}), "('--private-key', callback=utils.check_account, help=\n    'The privat key to sign the transaction')\n", (1390, 1489), False, 'import click\n'), ((1785, 1896), 'click.option', 'click.option', (['"""--private-key"""'], {'callback': 'utils.check_account', 'help': '"""The privat key to sign the transaction"""'}), "('--private-key', callback=utils.check_account, help=\n    'The privat key to sign the transaction')\n", (1797, 1896), False, 'import click\n')]