import java.io.*;
import java.net.*;

public class Client_Customer {
    public static void main(String[] args) {

        // TODO - Fill out the following questionairre: 

        double averageBeefPurchase = 2; // How many pounds of beef do you typically purchase when you buy groceries?
        double averageVariationInBeefPurchase = 0.5; // How much do you typically vary from the above amount (also in pounds)?

        double averagePorkPurchase = 4; // How many pounds of pork do you typically purchase when you buy groceries?
        double averageVariationInPorkPurchase = 0.5; // How much do you typically vary from the above amount (also in pounds)?

        double averageChickenPurchase = 6; // How many pounds of chicken do you typically purchase when you buy groceries?
        double averageVariationInChickenPurchase = 0.5; // How much do you typically vary from the above amount (also in pounds)?

        double averageEggsPurchase = 2; // How many eggs do you typically purchase when you buy groceries (amount in dozens)?
        double averageVariationInEggsPurchase = 0.5; // How much do you typically vary from the above amount (also in dozens)?

        // End of TODO section

        Customer myCustomer = new Customer(averageBeefPurchase, averageVariationInBeefPurchase, averagePorkPurchase, averageVariationInPorkPurchase, averageChickenPurchase, averageVariationInChickenPurchase, averageEggsPurchase, averageVariationInEggsPurchase);

        try {
            // Create client socket and connect to the server
            Socket clientSocket = new Socket("localhost", 12345);
            System.out.println("Connected to server.");

            // Send request to server
            PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
            String request = "doTransaction," + myCustomer.getBeefPreference().generate() + "," + myCustomer.getPorkPreference().generate() + "," + myCustomer.getChickenPreference().generate() + "," + myCustomer.getEggsPreference().generate();
            out.println(request);
            System.out.println("Sent request to server: " + request);

            // Receive response from server
            BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
            StringBuilder responseBuilder = new StringBuilder();
            String line;
            while ((line = in.readLine()) != null) {
                responseBuilder.append(line).append("\n");
            }
            String response = responseBuilder.toString();
            System.out.print("Received response from server: " + response);

            // Close connections
            in.close();
            out.close();
            clientSocket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}