DEFINE FUNCTION OVERWRITE fn::vm_price_per_minute(
	$vm_id: record
) {
    LET $vm = (select * from $vm_id)[0];
    LET $ip_price = 0;
    IF $vm.public_ipv4.len() > 0 {
        $ip_price = 10
    };
    RETURN (
      ($vm.vcpus * 10) + (($vm.memory_mb + 256) / 200) + ($vm.disk_size_gb / 10) + $ip_price)
    * $vm.price_per_unit;
};

DEFINE FUNCTION OVERWRITE fn::delete_vm(
	$vm_id: record
) {
    LET $vm = (select * from $vm_id)[0];
    LET $account = $vm.in;
    LET $deleted_vm = $vm.patch([{
		'op': 'replace',
		'path': 'id',
		'value': type::record("deleted_vm:" + record::id($vm.id))
    }]);
    IF $vm.locked_nano >= 0 {
        UPDATE $account SET balance += $vm.locked_nano;
    };
    INSERT RELATION INTO deleted_vm ( $deleted_vm );
    DELETE $vm.id;
};

