package org.academiadecodigo.bootcamp.model;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * MIT License
 * (c) 2017 Ricardo Constantino
 */

public class CodeCadet {
    private User user;
    private Gender gender;
    private String address;
    private String city;
    private String phonenumber;
    private Bootcamp bootcamp;
    private Date birthdate;
    private final DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");


    public CodeCadet(User user) {
        this.user = user;
        this.gender = Gender.MALE;
        this.address = "Rua Aires Oliveira, 18";
        this.city = "City of Angels";
        this.phonenumber = "912345678";
        setBirthdate("1987/10/17");
    }

    public void setBootcamp(Bootcamp bootcamp) {
        this.bootcamp = bootcamp;
    }

    public String getName() {
        return user.getUsername();
    }

    public Gender getGender() {
        return gender;
    }

    public String getAddress() {
        return address;
    }

    public String getCity() {
        return city;
    }

    public String getPhone() {
        return phonenumber;
    }

    public String getBirthdate() {
        return dateFormat.format(birthdate);
    }

    public void setGender(Gender gender) {
        this.gender = gender;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public void setPhone(String phone) {
        this.phonenumber = phone;
    }

    public void setBirthdate(Date birthdate) {
        this.birthdate = birthdate;
    }

    public void setBirthdate(String birthdate) {
        try {
            this.birthdate = dateFormat.parse(birthdate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Override
    public String toString() {
        return "CodeCadet{" +
                "name=" + user.getUsername() + ", " +
                "gender=" + gender + ", " +
                "address=" + address + ", " +
                "city=" + city + ", " +
                "phone=" + phonenumber + ", " +
                "birthdate=" + birthdate +
                "}";
    }

    public enum Gender {
        MALE,
        FEMALE,
        OTHER;
    }
}
