package ru.bmn.web.hsdb.model.entity.hs;

import javax.persistence.*;
import java.util.Set;

@Entity
@Table(
	uniqueConstraints = {
		@UniqueConstraint(
			columnNames = {"name"}
		)
	}
)
public class Card {
	@Id
	@GeneratedValue
	private Integer id;

	private String name;
	private int manaCost;
	private int attack;
	private int health;
	private String text;
	private String aboutText;
	private boolean collectible;
	private String externalUrl;

	private String imageUrl;
	private String goldImageUrl;

	@ManyToMany(mappedBy = "cards")
	private Set<CharacterClass> characters;

	@OneToOne
	@JoinColumn(name = "type_id")
	private Type type;

	@OneToOne
	@JoinColumn(name = "race_id")
	private Race race;

	@OneToOne
	@JoinColumn(name = "series_id")
	private Series series;

	@OneToOne
	@JoinColumn(name = "rarity_id")
	private Rarity rarity;

	@OneToOne
	@JoinColumn(name = "artist_id")
	private Artist artist;

	@OneToMany(mappedBy = "card")
	private Set<Sound> sounds;

	@ManyToMany(mappedBy = "cards")
	private Set<Mechanic> mechanic;

	public Integer getId() {
		return id;
	}


	public Card setId(Integer id) {
		this.id = id;
		return this;
	}

	public String getName() {
		return name;
	}

	public Card setName(String name) {
		this.name = name;
		return this;
	}

	public int getManaCost() {
		return manaCost;
	}

	public Card setManaCost(int manaCost) {
		this.manaCost = manaCost;
		return this;
	}

	public int getAttack() {
		return attack;
	}

	public Card setAttack(int attack) {
		this.attack = attack;
		return this;
	}

	public int getHealth() {
		return health;
	}

	public Card setHealth(int health) {
		this.health = health;
		return this;
	}

	public String getText() {
		return text;
	}

	public Card setText(String text) {
		this.text = text;
		return this;
	}

	public String getAboutText() {
		return aboutText;
	}

	public Card setAboutText(String aboutText) {
		this.aboutText = aboutText;
		return this;
	}

	public boolean isCollectible() {
		return collectible;
	}

	public Card setCollectible(boolean collectible) {
		this.collectible = collectible;
		return this;
	}

	public String getImageUrl() {
		return imageUrl;
	}

	public Card setImageUrl(String imageUrl) {
		this.imageUrl = imageUrl;
		return this;
	}

	public String getGoldImageUrl() {
		return goldImageUrl;
	}

	public Card setGoldImageUrl(String goldImageUrl) {
		this.goldImageUrl = goldImageUrl;
		return this;
	}

	public Type getType() {
		return type;
	}

	public Card setType(Type type) {
		this.type = type;
		return this;
	}

	public Race getRace() {
		return race;
	}

	public Card setRace(Race race) {
		this.race = race;
		return this;
	}

	public Series getSeries() {
		return series;
	}

	public Card setSeries(Series series) {
		this.series = series;
		return this;
	}

	public Rarity getRarity() {
		return rarity;
	}

	public Card setRarity(Rarity rarity) {
		this.rarity = rarity;
		return this;
	}

	public Artist getArtist() {
		return artist;
	}

	public Card setArtist(Artist artist) {
		this.artist = artist;
		return this;
	}

	public Set<Sound> getSounds() {
		return sounds;
	}

	public Card setSounds(Set<Sound> sounds) {
		this.sounds = sounds;
		return this;
	}

	public Set<Mechanic> getMechanic() {
		return mechanic;
	}

	public Card setMechanic(Set<Mechanic> mechanic) {
		this.mechanic = mechanic;
		return this;
	}

	public Set<CharacterClass> getCharacters() {
		return characters;
	}

	public Card setCharacters(Set<CharacterClass> characters) {
		this.characters = characters;
		return this;
	}

	public String getExternalUrl() {
		return externalUrl;
	}

	public Card setExternalUrl(String externalUrl) {
		this.externalUrl = externalUrl;
		return this;
	}
}

@@ -575,33 +575,64 @@
 ers;%0A%0A%09@OneToOne
+(cascade = CascadeType.PERSIST)
 %0A
-
 %09@JoinColumn(nam
@@ -669,32 +669,63 @@
 ype;%0A%0A%09@OneToOne
+(cascade = CascadeType.PERSIST)
 %0A%09@JoinColumn(na
@@ -763,32 +763,63 @@
 ace;%0A%0A%09@OneToOne
+(cascade = CascadeType.PERSIST)
 %0A%09@JoinColumn(na
@@ -863,32 +863,63 @@
 ies;%0A%0A%09@OneToOne
+(cascade = CascadeType.PERSIST)
 %0A%09@JoinColumn(na
@@ -961,16 +961,16 @@
 arity;%0A%0A
-
 %09@OneToO
@@ -971,16 +971,47 @@
 OneToOne
+(cascade = CascadeType.PERSIST)
 %0A%09@JoinC

fix save relationships