package cz.utb.tadis.attacks.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;

import javax.persistence.*;
import javax.validation.constraints.*;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.List;

@Entity
@Table(name = "attacks")
public class Attack {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotBlank
    @Size(max = 50)
    private String country;

    @NotBlank
    @Size(max = 50)
    private String city;

    @NotNull
    private LocalDate date;

    @JsonFormat(pattern="HH:mm")
    private LocalTime time;

    @JsonFormat(pattern="HH:mm")
    private LocalTime peak;

    private Float latitude;

    private Float longitude;

    @Size(max = 200)
    private String softTargetDescription;

    @NotNull
    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
    @JoinColumn(name = "attackId")
    private List<SoftTargetType> softTargetTypes;

    @Enumerated(EnumType.STRING)
    private ClosedResponse terror;

    @Enumerated(EnumType.STRING)
    private Epicenter epicenter;

    @Enumerated(EnumType.STRING)
    private ModusOperandi modusOperandi;

    @Size(max = 200)
    private String modusOperandiDetail;

    @Enumerated(EnumType.STRING)
    private ClosedResponse entranceSecurity;

    @Size(max = 200)
    private String terroristOrganization;

    @NotNull
    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
    @JoinColumn(name = "attackId")
    private List<Attacker> attackers;

    @JsonIgnore
    private Integer attackersCount;

    private Integer deaths;

    private Integer injured;

    private Integer potentialVictims;

    @NotNull
    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
    @JoinColumn(name = "attackId")
    private List<RelatedAttack> relatedAttacks;

    @Size(max = 1000)
    private String note;

    @Size(max = 1000)
    private String link;

    public Attack() {
    }

    public Attack(@NotBlank @Size(max = 50) String country, @NotBlank @Size(max = 50) String city, @NotNull LocalDate date, LocalTime time, LocalTime peak, Float latitude, Float longitude, @Size(max = 200) String softTargetDescription, @NotNull List<SoftTargetType> softTargetTypes, ClosedResponse terror, Epicenter epicenter, ModusOperandi modusOperandi, @Size(max = 200) String modusOperandiDetail, ClosedResponse entranceSecurity, @Size(max = 200) String terroristOrganization, @NotNull List<Attacker> attackers, Integer attackersCount, Integer deaths, Integer injured, Integer potentialVictims, @NotNull List<RelatedAttack> relatedAttacks, @Size(max = 1000) String note, @Size(max = 1000) String link) {
        this.country = country;
        this.city = city;
        this.date = date;
        this.time = time;
        this.peak = peak;
        this.latitude = latitude;
        this.longitude = longitude;
        this.softTargetDescription = softTargetDescription;
        this.softTargetTypes = softTargetTypes;
        this.terror = terror;
        this.epicenter = epicenter;
        this.modusOperandi = modusOperandi;
        this.modusOperandiDetail = modusOperandiDetail;
        this.entranceSecurity = entranceSecurity;
        this.terroristOrganization = terroristOrganization;
        this.attackers = attackers;
        this.attackersCount = attackersCount;
        this.deaths = deaths;
        this.injured = injured;
        this.potentialVictims = potentialVictims;
        this.relatedAttacks = relatedAttacks;
        this.note = note;
        this.link = link;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getCity() {
        return city;
    }

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

    @JsonFormat(pattern="d.M.YYYY")
    public LocalDate getDate() {
        return date;
    }

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
    public void setDate(LocalDate date) {
        this.date = date;
    }

    public LocalTime getTime() {
        return time;
    }

    public void setTime(LocalTime time) {
        this.time = time;
    }

    public LocalTime getPeak() {
        return peak;
    }

    public void setPeak(LocalTime peak) {
        this.peak = peak;
    }

    public Float getLatitude() {
        return latitude;
    }

    public void setLatitude(Float latitude) {
        this.latitude = latitude;
    }

    public Float getLongitude() {
        return longitude;
    }

    public void setLongitude(Float longitude) {
        this.longitude = longitude;
    }

    public List<SoftTargetType> getSoftTargetTypes() {
        return softTargetTypes;
    }

    public void setSoftTargetTypes(List<SoftTargetType> softTargetTypes) {
        this.softTargetTypes = softTargetTypes;
    }

    public String getSoftTargetDescription() {
        return softTargetDescription;
    }

    public void setSoftTargetDescription(String softTargetDescription) {
        this.softTargetDescription = softTargetDescription;
    }

    public ClosedResponse getTerror() {
        return terror;
    }

    public void setTerror(ClosedResponse terror) {
        this.terror = terror;
    }

    public Epicenter getEpicenter() {
        return epicenter;
    }

    public void setEpicenter(Epicenter epicenter) {
        this.epicenter = epicenter;
    }

    public ModusOperandi getModusOperandi() {
        return modusOperandi;
    }

    public void setModusOperandi(ModusOperandi modusOperandi) {
        this.modusOperandi = modusOperandi;
    }

    public String getModusOperandiDetail() {
        return modusOperandiDetail;
    }

    public void setModusOperandiDetail(String modusOperandiDetail) {
        this.modusOperandiDetail = modusOperandiDetail;
    }

    public ClosedResponse getEntranceSecurity() {
        return entranceSecurity;
    }

    public void setEntranceSecurity(ClosedResponse entranceSecurity) {
        this.entranceSecurity = entranceSecurity;
    }

    public String getTerroristOrganization() {
        return terroristOrganization;
    }

    public void setTerroristOrganization(String terroristOrganization) {
        this.terroristOrganization = terroristOrganization;
    }

    public List<Attacker> getAttackers() {
        return attackers;
    }

    public void setAttackers(List<Attacker> attackers) {
        this.attackers = attackers;
    }

    public Integer getAttackersCount() {
        return attackersCount;
    }

    public void setAttackersCount(Integer attackersCount) {
        this.attackersCount = attackersCount;
    }

    public Integer getDeaths() {
        return deaths;
    }

    public void setDeaths(Integer deaths) {
        this.deaths = deaths;
    }

    public Integer getInjured() {
        return injured;
    }

    public void setInjured(Integer injured) {
        this.injured = injured;
    }

    public Integer getPotentialVictims() {
        return potentialVictims;
    }

    public void setPotentialVictims(Integer potentialVictims) {
        this.potentialVictims = potentialVictims;
    }

    public List<RelatedAttack> getRelatedAttacks() {
        return relatedAttacks;
    }

    public void setRelatedAttacks(List<RelatedAttack> relatedAttacks) {
        this.relatedAttacks = relatedAttacks;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public String getLink() {
        return link;
    }

    public void setLink(String link) {
        this.link = link;
    }
}
