package com.systelab.seed.patientallergy.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.systelab.seed.allergy.entity.Allergy;
import com.systelab.seed.patient.entity.Patient;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.MapsId;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.time.LocalDate;


@Entity
@Getter
@Setter
@NoArgsConstructor
public class PatientAllergy {


    @JsonIgnore
    @EmbeddedId
    private PatientAllergyId id;

    @JsonIgnore
    @ManyToOne
    @MapsId("patientId")
    private Patient patient;

    @ManyToOne
    @MapsId("allergyId")
    private Allergy allergy;

    @Schema(description = "ISO 8601 Format.", example = "1986-01-22T23:28:56.782Z")
    private LocalDate lastOccurrence;
    @Schema(description = "ISO 8601 Format.", example = "1986-01-22T23:28:56.782Z")
    private LocalDate assertedDate;

    @NotNull
    @Size(min = 1, max = 255)
    private String note;

    public PatientAllergy(Patient patient, Allergy allergy) {
        this.id = new PatientAllergyId(patient.getId(), allergy.getId());
        this.patient = patient;
        this.allergy = allergy;
    }
}

@@ -144,16 +144,87 @@
 llergy;%0A
+import com.systelab.seed.infrastructure.jaxb.JsonLocalDateTypeAdapter;%0A
 import c
@@ -264,16 +264,16 @@
 atient;%0A
-
 import i
@@ -619,16 +619,78 @@
 s.Size;%0A
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;%0A
 import j
@@ -1008,16 +1008,72 @@
 lergy;%0A%0A
+    @XmlJavaTypeAdapter(JsonLocalDateTypeAdapter.class)%0A
     @Sch
@@ -1140,32 +1140,32 @@
 23:28:56.782Z%22)%0A
-
     private Loca
@@ -1185,16 +1185,73 @@
 urrence;
+%0A%0A    @XmlJavaTypeAdapter(JsonLocalDateTypeAdapter.class)
 %0A    @Sc

Set an XMLAdapter for the LocalDate (#75)