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 = "City")
@Table(name = "CITIES")
//this is for oracle db @SequenceGenerator(name = "CITY_SEQ", sequenceName = "CITY_SEQ", allocationSize = 1)
@EntityListeners( { BaseEntityListener.class })
public class City extends BaseEntity
{
    private String name;
    private String internationalName;
    private Collection<District> districts;

    public City()
    {
        entityName = "City";
        this.districts = new ArrayList<District>();
    }
    
    public City(int id, String name)
    {
        entityName = "City";
        this.districts = new ArrayList<District>();
        
        this.id=id;
        this.name=name;
    }

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

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

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

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

    public void setDistricts(Collection<District> districts)
    {
        this.districts = districts;
    }

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

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

    @OneToMany(targetEntity = District.class, cascade = { CascadeType.ALL })
    @org.hibernate.annotations.Cascade( { org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
    @JoinColumn(name = "CITYID")
    public Collection<District> getDistricts()
    {
        return districts;
    }

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