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


import com.acme.model.domain.ad.entity.Currency;
import com.acme.model.domain.ad.entity.Unit;
import com.acme.structure.BaseEntity;
import com.acme.structure.BaseEntityListener;

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.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;


@Entity(name = "OrderDetail")
@Table(name = "ORDERDETAILS")
//this is for oracle db @SequenceGenerator(name = "ORDERDETAIL_SEQ", sequenceName = "ORDERDETAIL_SEQ", allocationSize = 1)
@EntityListeners( { BaseEntityListener.class })
public class OrderDetail extends BaseEntity
{
    private Service service;
    private Unit unit;
    private double quantity;
    private double calculatedPrice;
    private Currency currency;
    private OrderDetailComment orderDetailComment;

    public OrderDetail()
    {
        this.entityName = "OrderDetail";
    }

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

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

    public void setService(Service service)
    {
        this.service = service;
    }

    @ManyToOne(targetEntity = Service.class, cascade = { })
    @JoinColumn(name = "SERVICEID")
    public Service getService()
    {
        return service;
    }

    public void setUnit(Unit unit)
    {
        this.unit = unit;
    }

    @ManyToOne(targetEntity = Unit.class, cascade = { })
    @JoinColumn(name = "UNITID")
    public Unit getUnit()
    {
        return unit;
    }

    public void setQuantity(double quantity)
    {
        this.quantity = quantity;
    }

    @Column(name = "QUANTITY")
    public double getQuantity()
    {
        return quantity;
    }

    public void setCalculatedPrice(double calculatedPrice)
    {
        this.calculatedPrice = calculatedPrice;
    }

    @Column(name = "CALCULATEDPRICE")
    public double getCalculatedPrice()
    {
        return calculatedPrice;
    }

    public void setCurrency(Currency currency)
    {
        this.currency = currency;
    }

    @ManyToOne(targetEntity = Currency.class, cascade = { })
    @JoinColumn(name = "CURRENCYID")
    public Currency getCurrency()
    {
        return currency;
    }

    public void setOrderDetailComment(OrderDetailComment orderDetailComment)
    {
        this.orderDetailComment = orderDetailComment;
    }

    @OneToOne(targetEntity = OrderDetailComment.class, cascade = { CascadeType.ALL })
    @org.hibernate.annotations.Cascade( { org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
    @JoinColumn(name = "ORDERDETAILCOMMENTID")
    public OrderDetailComment getOrderDetailComment()
    {
        return orderDetailComment;
    }

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