# Phase 4: Vehicle Monitoring
# Secure Multi-Party Computation (SMPC) techniques using Sharemind MPC software - https://docs.sharemind.cyber.ee/2022.03/prologue
# Virtual Machine could be downloaded here - https://sharemind.cyber.ee/sharemind-mpc/
# sharemind library - https://github.com/sharemind-sdk/build-sdk
# shareprom library - https://github.com/Elkoumy/shareprom
# Author: Norbert Lovinger; xlovin00@vutbr.cz
# Date: 16th May 2023

import sharemind
import shareprom 

# Define the number of parties involved in the computation (3 - max)
NUM_PARTIES = 3

# Involved computational parties
VEHICLE = 1
USER = 2
CAR_SHARING_APP = 3

# Generate some random integers to use as secret data
vehicle_miles = 10 # for example, includes the travelled distance in km
user_price = 4 # for example, represents the price per km for this user
additional_price = 20 # for example, includes additional costs such as highway tolls or parking fees

# Connect to the Sharemind MPC SDK Virtual server and create the computation
with sharemind.Connection('localhost', 12345) as conn:
    with conn.session() as session:
        # Create secret values from the integers
        s1 = session.input(vehicle_miles)
        s2 = session.input(user_price)
        s3 = session.input(additional_price)

        # Send the secret values to the Sharemind server
        session.output(vehicle_miles, "vehicle")
        session.output(user_price, "user")
        session.output(additional_price, "app")
        
        # Receive the result from the Sharemind server program with a name of the value
        result_secret = session.input_from("C", ["output"])

        # Reveal the final_price to the appropriate parties
        final_price = session.output(result_secret)

        # Print the final result
        print("Final price for car rental:", final_price)
