package com.huixinpn.dionysus.domain.appointment;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

import com.huixinpn.dionysus.domain.AbstractDionysusAuditable;
import com.huixinpn.dionysus.domain.AbstractDionysusNotifiable;
import com.huixinpn.dionysus.domain.user.Consultant;
import com.huixinpn.dionysus.domain.user.User;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
 * Created by huanghao on 4/4/15.
 * Used to represent the one-one appointment
 */


@Entity
@Table(name = "appointments")
public class Appointment extends AbstractDionysusNotifiable<User> {

  private static final long serialVersionUID = 4106091118545531113L;

  @NotNull
  @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
  private User user;

  @NotNull
  @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
  private Consultant consultant;

  @Column(name = "state")
  @Enumerated(EnumType.STRING)
  private AppointmentStatus state;

  @Column(name = "approach")
  @Enumerated(EnumType.STRING)
  private AppointmentApproach approach;

  @Column(name = "calendar")
  @Temporal(TemporalType.DATE)
  private Calendar date;

  @Lob
  @Column(name = "reason")
  private String reason;

  public Appointment() {
      this.state = AppointmentStatus.WAITING;
  }

  public Appointment(User user, Consultant consultant, AppointmentApproach approach, Calendar date, String reason) {
    this.user = user;
    this.consultant = consultant;
    this.approach = approach;
    this.state = AppointmentStatus.WAITING;
    this.date = date;
    this.reason = reason;
  }

  public User getUser() {
    return user;
  }

  public void setUser(User user) {
    this.user = user;
  }

  public Consultant getConsultant() {
    return consultant;
  }

  public void setConsultant(Consultant consultant) {
    this.consultant = consultant;
  }

  public AppointmentStatus getState() {
    return state;
  }

  public void setState(AppointmentStatus state) {
    this.state = state;
  }

  public AppointmentApproach getApproach() {
    return approach;
  }

  public void setApproach(AppointmentApproach approach) {
    this.approach = approach;
  }

  public Calendar getDate() {
    return date;
  }

  public void setDate(Calendar date) {
    this.date = date;
  }

  public String getReason() {
    return reason;
  }

  public void setReason(String reason) {
    this.reason = reason;
  }

  @Override
  public String toString() {
    return "Appointment{" +
        "user=" + user +
        ", consultant=" + consultant +
        ", state=" + state +
        ", approach=" + approach +
        ", date=" + date +
        ", reason='" + reason + '\'' +
        '}';
  }

  @Override
  public String getSummary(){
        return this.getReason();
  }


    @Override
    public List<User> sendTo(){
        User user = this.getUser();
        User consultant = this.getConsultant();
        List<User> users = new ArrayList<User>();

        if(consultant!=null){
            users.add(consultant);
        }

        if(user!=null){
            users.add(user);
        }

        return users;

    }
}

@@ -55,136 +55,51 @@
 ort 
-javax.persistence.*;%0Aimport javax.validation.constraints.NotNull;%0A%0Aimport com.huixinpn.dionysus.domain.AbstractDionysusAuditable
+com.fasterxml.jackson.annotation.JsonFormat
 ;%0Aim
@@ -261,16 +261,89 @@
 .User;%0A%0A
+import javax.persistence.*;%0Aimport javax.validation.constraints.NotNull;%0A
 import j
@@ -1117,34 +1117,80 @@
 %0A  @
-Temporal(TemporalType.DATE
+JsonFormat(shape = JsonFormat.Shape.STRING, pattern = %22yyyy/MM/dd HH:mm%22
 )%0A  
@@ -1302,18 +1302,16 @@
 ) %7B%0A    
-  
 this.sta
@@ -2786,22 +2786,19 @@
 ummary()
+ 
 %7B%0A
-    
     retu
@@ -2824,18 +2824,16 @@
 ;%0A  %7D%0A%0A%0A
-  
   @Overr
@@ -2838,18 +2838,16 @@
 rride%0A  
- 
- 
 public L
@@ -2864,26 +2864,23 @@
 sendTo()
+ 
 %7B%0A    
-  
-  
 User use
@@ -2903,20 +2903,16 @@
 ();%0A    
-  
-  
 User con
@@ -2947,20 +2947,16 @@
 ();%0A    
-  
-  
 List%3CUse
@@ -2994,22 +2994,19 @@
 );%0A%0A    
-  
-  
 if
+ 
 (consult
@@ -3008,31 +3008,34 @@
 nsultant
+ 
 !=
+ 
 null)
+ 
 %7B%0A      
       us
@@ -3018,38 +3018,32 @@
 = null) %7B%0A      
-  
-    
 users.add(consul
@@ -3053,49 +3053,39 @@
 t);%0A
-    
     %7D%0A%0A
-    
     if
+ 
 (user
+ 
 !=
+ 
 null)
+ 
 %7B%0A
-      
     
@@ -3107,27 +3107,19 @@
 r);%0A    
-  
-  
 %7D%0A%0A
-    
     retu
@@ -3129,16 +3129,14 @@
 users;%0A%0A
-  
   %7D%0A%7D%0A

add Appointment date format limitation