package com.lavandadelpatio.model;

import com.fasterxml.jackson.annotation.JsonView;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Entity
public class Person {
	public interface Basic{}
	public interface Full{}
    /**
     * Person ID
     */
	@JsonView(Basic.class)
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long personId;
    /**
     * Person firstName
     */
	@JsonView(Basic.class)
    private String firstName;
    /**
     * Person lastName
     */
	@JsonView(Basic.class)
    private String lastName;
    /**
     * Person birthday
     */
	@JsonView(Full.class)
    private Date datePerson;
	private static SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");

    
	/**
     * Person nationality
     */
    @JsonView(Full.class)
    private String nationality;

    /**
     * Profile photo
     */
    @JsonView(Full.class)
    private String photo = "";

    /**
     * Magic constructor for Spring
     */
    protected Person() {}

    /**
     *
     * @param firstname
     * @param lastname
     * @param datePerson
     * @param nationality
     * @param photo
     */
    public Person(String firstname, String lastname, Date datePerson, String nationality, String photo) {
        this.firstName = firstname;
        this.lastName = lastname;
        this.datePerson = datePerson;
        this.nationality = nationality;
        this.photo = photo;
    }

    /**
     *
     * @param firstname
     * @param lastname
     * @param datePerson
     * @param nationality
     * @param photo
     */
    public Person(String firstname, String lastname, String datePerson, String nationality, String photo) throws ParseException {
        this.firstName = firstname;
        this.lastName = lastname;
        this.datePerson = formatter.parse(datePerson);
        this.nationality = nationality;
        this.photo = photo;
    }

    /**
     * Return Person ID
     * @return
     */
    public long getPersonId() {
        return personId;
    }

    /**
     * Return Person firstName
     * @return
     */
    public String getFirstName() {
        return firstName;
    }

    /**
     * Set the Person firstName
     * @param firstName
     */
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    /**
     * Get person Lastname
     * @return
     */
    public String getLastName() {
        return lastName;
    }

    /**
     * set person lastName
     * @param lastName
     */
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    /**
     * Get person date
     * @return
     */

    public String getDatePerson() {
		return dateFormat(datePerson);
				//formatter.format(datePerson);
    }
    
    
 

    /**
     * set person birthdate
     * @param datePerson
     */
    public void setBirthdate(Date datePerson) {
        this.datePerson = datePerson;
    }

    /**
     * get person nationality
     * @return
     */
    public String getNationality() {
        return nationality;
    }

    /**
     * set Person nationality
     * @param nationality
     */
    public void setNationality(String nationality) {
        this.nationality = nationality;
    }

    public String getPhoto() {
        return photo;
    }

    public void setPhoto(String photo) {
        this.photo = photo;
    }
    private String dateFormat(Date d) {
		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
		return sdf.format(d);
	}

}

