package cz.utb.tadis.map.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import cz.utb.tadis.attacks.model.ModusOperandi;
import cz.utb.tadis.attacks.model.SoftTargetType;

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

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

    @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;

    @DecimalMin("-90")
    @DecimalMax("90")
    private BigDecimal latitude;

    @DecimalMin("-180")
    @DecimalMax("180")
    private BigDecimal longitude;

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

    @Enumerated(EnumType.STRING)
    private ModusOperandi modusOperandi;

    public MapAttack() {
    }

    public MapAttack(@NotBlank @Size(max = 50) String country, @NotBlank @Size(max = 50) String city, @NotNull LocalDate date, @DecimalMin("-90") @DecimalMax("90") BigDecimal latitude, @DecimalMin("-180") @DecimalMax("180") BigDecimal longitude, @NotNull List<SoftTargetType> softTargetTypes, ModusOperandi modusOperandi) {
        this.country = country;
        this.city = city;
        this.date = date;
        this.latitude = latitude;
        this.longitude = longitude;
        this.softTargetTypes = softTargetTypes;
        this.modusOperandi = modusOperandi;
    }

    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;
    }

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

    public BigDecimal getLatitude() {
        return latitude;
    }

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

    public BigDecimal getLongitude() {
        return longitude;
    }

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

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

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

    public ModusOperandi getModusOperandi() {
        return modusOperandi;
    }

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