package com.example.scoutingapp;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Locale;
import java.util.stream.Collectors;

public class MatchData {
    //Main Page
    private String scoutName;
    private String eventName;
    //Initial Page
    private int matchNumber = 0;
    private String teamNumber;
    private int startingPosition = 0;
    private boolean isBlueAlliance = false;

    private boolean isPractice = false;
    //Auto Page
    private boolean aLeave = false;

    private boolean onlyPreload = false;
    //Teleop Page
    private int tL1 = 0;
    private int aHub = 0;
    private int tHub = 0;
    private int eMinors = 0;
    private int eMajor = 0;
    private boolean tDied;
    private int aClimb = 0;

    private int defense = 0;

    private int tClimb = 0;
    private String eNote;

    public MatchData() {
        scoutName = "NO NAME PROVIDED";
        eventName = "Practice - NO EVENT";
        teamNumber = "0000";
        eNote = "NO NOTES PROVIDED";
    }

    public String makeCSVString() {
        String[] matchData = {
                eventName,
                String.valueOf(matchNumber),
                teamNumber,
                String.valueOf(startingPosition),
                "Auto",
                String.valueOf(aHub),
                String.valueOf(aClimb),
                String.valueOf(aLeave),
                String.valueOf(onlyPreload),
                "Teleop",
                String.valueOf(tHub),
                String.valueOf(tClimb),
                String.valueOf(tDied),
                eNote,
                String.valueOf(eMajor),
                String.valueOf(eMinors),
                String.valueOf(defense),
                scoutName,
                getTimestamp() + " "
        };

        return String.join("@#@", matchData);

    }



    public String getCSVFileName() {
        return eventName + matchNumber + teamNumber + ".csv";
    }

    public static String getTimestamp() {
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy HH:mm:ss.SSS", Locale.getDefault());
        return sdf.format(new Date());
    }

    public String getScoutName() {
        return scoutName;
    }

    public void setScoutName(String scoutName) {
        this.scoutName = scoutName;
    }

    public String getEventName() {
        return eventName;
    }

    public void setEventName(String eventName) {
        this.eventName = eventName;
    }

    public int getMatchNumber() {
        return matchNumber;
    }

    public void setMatchNumber(int matchNumber) {
        this.matchNumber = matchNumber;
    }

    public String getTeamNumber() {
        return teamNumber;
    }

    public void setTeamNumber(String teamNumber) {
        this.teamNumber = teamNumber;
    }

    public int getStartingPosition() {
        return startingPosition;
    }

    public void setStartingPosition(int startingPosition) {
        this.startingPosition = startingPosition;
    }

    public boolean isBlueAlliance() {
        return isBlueAlliance;
    }

    public void setBlueAlliance(boolean blueAlliance) {
        isBlueAlliance = blueAlliance;
    }

    public int getaHub() {
        return aHub;
    }

    public void setaHub(int aHub) {
        this.aHub = Math.max(0, aHub);
    }

    public int gettHub() {
        return tHub;
    }

    public void settHub(int tHub) {
        this.tHub = Math.max(0, tHub);
    }

    public void seteMajor(int eMajor) {
        this.eMajor = Math.max(0, eMajor);
    }

    public int getDefense() {
        return defense;
    }

    public void setDefense(int defense) {
        this.defense = defense;
    }


    public int geteMajor() {
        return eMajor;
    }
    public void seteMinors(int eMinors) {
        this.eMinors = Math.max(0, eMinors);
    }

    public int geteMinors() {
        return eMinors;
    }

    public void setaOnlyPreload (boolean onlyPreload) {
        this.onlyPreload = onlyPreload;
    }

    public boolean isaOnlyPreload () {
        return onlyPreload;
    }


    public int getaClimb() {
        return aClimb;
    }

    public int gettClimb() {
        return tClimb;
    }

    public boolean istDied() {
        return tDied;
    }

    public void settDied(boolean tCanLeave) {
        this.tDied = tCanLeave;
    }

    public boolean isaLeave() {
        return aLeave;
    }

    public void setaLeave(boolean aLeave) {
        this.aLeave = aLeave;
    }


    public void settClimb(int tClimb) {
        this.tClimb = Math.max(0, tClimb);
    }
    public void setaClimb(int aClimb) {
        this.aClimb = Math.max(0, aClimb);
    }


    public String geteNote() {
        return eNote;
    }

    public void seteNote(String eNote) {
        this.eNote = eNote;
    }

    public boolean isPractice() {
        return isPractice;
    }

    public void setPractice(boolean blueAlliance) {
        isPractice = blueAlliance;
    }

}
