import java.util.*;
import java.io.*;
import java.time.LocalDate;

/**
 * WIP
 *
 *
 * @Author: Danylo Mirin
 * @Copyright 2019; see license on GitHub
 *
 * Class contains all the Periods and manipulates the data
 * Class does not check for null
 * Class does not contain any exception handling as of 2019/10/19
 *
 * Standard Class Functionality has not been overridden - there's only one manager
 * Maybe organize a separate class to handle I/O?
 * Periods organize receipts
 *
 * DATE FORMAT IS STILL YYYY-MM-DD
 */

public class ReceiptManager {
    private ArrayList<Period> data;
    private File file;
    private FileWriter writer;
    public ReceiptManager() {
        data = new ArrayList<Period>();
        file = new File("data.csv");

        try {
            writer = new FileWriter(file);
        } catch(IOException ioe) {
            ioe.printStackTrace();
        }
    }

    public static void main(String[] args) {
        ReceiptManager receiptManager = new ReceiptManager();    }
        Scanner scanner = new Scanner(System.in);
        String input = "";
        while(true) {
            input = scanner.nextLine();
            if(input.equals("stop") || input.equals("exit"))
                break;
            if(input.equals("New Item".toLowerCase())) {
                System.out.println("I need the transaction number, amount (in USD), date (YYYY-MM-DD), category, place of purchase (or sale).");
                boolean valid = false;
                while(!valid) {
                    System.out.println("Enter info separated by commas, NO spaces after commas. 5 bits of information req'd");
                    input = scanner.nextLine();
                    String[] bits = input.split(",");
                    if(bits.length == 5) {
                        int transactionNumber = Integer.parseInt(bits[0]);
                        double amount = Double.parseDouble(bits[1]);
                        Receipt r = new Receipt(transactionNumber, amount, bits[2], bits[3], bits[4]);
                    }
            }

        }
    }

    public boolean add(Receipt r) {
        data.add(r);
    }

    public void writeData() throws IOException {
        for(Period p : data)
            writer.write(p.returnAll());
        writer.flush();
        writer.close();
    }
}