package com.acme.model.domain.ad.entity;


import com.acme.structure.BaseEntity;
import com.acme.structure.BaseEntityListener;

import java.util.ArrayList;
import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;


@Entity(name = "Country")
@Table(name = "COUNTRIES")
//this is for oracle db @SequenceGenerator(name = "COUNTRY_SEQ", sequenceName = "COUNTRY_SEQ", allocationSize = 1)
@EntityListeners( { BaseEntityListener.class })
public class Country extends BaseEntity
{
    private String code;
    private String name;
    private String internationalName;
    private Collection<City> cities;

    public Country()
    {
        entityName = "Country";
        this.cities = new ArrayList<City>();
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO) //, this is for oracle db, generator = "COUNTRY_SEQ")
    @Column(name = "ID")
    public int getId()
    {
        return id;
    }

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

    @Column(name = "CODE", length = 5)
    public String getCode()
    {
        return code;
    }

    public void setCode(String code)
    {
        this.code = code;
    }

    @Column(name = "NAME", length = 40)
    public String getName()
    {
        return name;
    }

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

    public void setInternationalName(String internationalName)
    {
        this.internationalName = internationalName;
    }

    @Column(name = "INTERNATIONALNAME", length = 40)
    public String getInternationalName()
    {
        return internationalName;
    }

    public void setCities(Collection<City> cities)
    {
        this.cities = cities;
    }

    @OneToMany(targetEntity = City.class, cascade = { CascadeType.ALL })
    @org.hibernate.annotations.Cascade( { org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
    @JoinColumn(name = "COUNTRYID")
    public Collection<City> getCities()
    {
        return cities;
    }

    @Override
    public String toString()
    {
        return getName() + " (" + getCode() + ")";
    }
}
