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


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

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity(name = "Address")
@Table(name = "ADDRESSES")
//this is for oracle db @SequenceGenerator(name = "ADDRESS_SEQ", sequenceName = "ADDRESS_SEQ", allocationSize = 1)
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "ADDRESSTYPE", discriminatorType = DiscriminatorType.STRING, length = 30)
@DiscriminatorValue("Address")
@EntityListeners( { BaseEntityListener.class })
public class Address extends BaseEntity
{
    private String street; //sokak, cadde
    private String region; //mahalle, semt
    private District district; //ilce
    private City city; //žehir
    private Country country;
    private String zip; //posta kodu
    private String addressType;

    public Address()
    {
        entityName = "Address";
        setAddressType(getEntityName());
    }

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

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

    @Column(name = "STREET", length = 200)
    public String getStreet()
    {
        return street;
    }

    public void setStreet(String street)
    {
        this.street = street;
    }

    @Column(name = "ZIP", length = 10)
    public String getZip()
    {
        return zip;
    }

    public void setZip(String zip)
    {
        this.zip = zip;
    }

    public void setRegion(String region)
    {
        this.region = region;
    }

    @Column(name = "REGION", length = 40)
    public String getRegion()
    {
        return region;
    }

    @ManyToOne(targetEntity = Country.class, cascade = { })
    @JoinColumn(name = "COUNTRYID")
    public Country getCountry()
    {
        return country;
    }

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

    public void setAddressType(String addressType)
    {
        this.addressType = addressType;
    }

    @Column(name = "DISTRICT", length = 30)
    public String getAddressType()
    {
        return addressType;
    }

    public void setDistrict(District district)
    {
        this.district = district;
    }

    @ManyToOne(targetEntity = District.class, cascade = { })
    @JoinColumn(name = "DISTRICTID")
    public District getDistrict()
    {
        return district;
    }

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


    @ManyToOne(targetEntity = City.class, cascade = { })
    @JoinColumn(name = "CITYID")
    public City getCity()
    {
        return city;
    }

    @Override
    public String toString()
    {
        return getStreet() + " " + getRegion() + " " + getDistrict() + " " + getCity() + " " + getZip();
    }
}
