@compiler >= 6

contract NodeRegistry =

  record user_info = {
    registry : address,
    joined   : int,
    tier     : string
  }

  record state = {
    owner : address,
    users : map(address, user_info)
  }

  stateful entrypoint init() : state =
    { owner = Call.caller, users = {} }

  function require_owner() =
    require(Call.caller == state.owner, "Only owner can call this")

  stateful entrypoint register_account(account: address, registry: address, tier: string) : bool =
    require_owner()
    require(!Map.member(account, state.users), "Already registered")
    let info = {
      registry = registry,
      joined = Chain.timestamp,
      tier = tier
    }
    put(state{users[account] = info})
    true

  entrypoint get_user_info(account: address) : user_info =
    require(Map.member(account, state.users), "Account not registered")
    state.users[account]

  entrypoint is_registered(account: address) : bool =
    Map.member(account, state.users)

  entrypoint get_registry(account: address) : address =
    require(Map.member(account, state.users), "Account not registered")
    state.users[account].registry

  stateful entrypoint update_tier(account: address, tier: string) : bool =
    require_owner()
    require(Map.member(account, state.users), "Account not registered")
    let user = state.users[account]
    put(state{users[account] = user{tier = tier}})
    true
