package com.cc.infosur.greendao;

import java.util.List;
import de.greenrobot.dao.DaoException;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. Enable "keep" sections if you want to edit. 
/**
 * Entity mapped to table STEP.
 */
public class Step {

    private Long id;
    private java.util.Date dateFrom;
    private java.util.Date dateTo;
    private String name;
    private Double latitude;
    private Double longitude;
    private byte[] icon;
    private long tripId;

    /** Used to resolve relations */
    private transient DaoSession daoSession;

    /** Used for active entity operations. */
    private transient StepDao myDao;

    private Trip trip;
    private Long trip__resolvedKey;

    private List<Excursion> excursions;
    private List<Detail> details;

    public Step() {
    }

    public Step(Long id) {
        this.id = id;
    }

    public Step(Long id, java.util.Date dateFrom, java.util.Date dateTo, String name, Double latitude, Double longitude, byte[] icon, long tripId) {
        this.id = id;
        this.dateFrom = dateFrom;
        this.dateTo = dateTo;
        this.name = name;
        this.latitude = latitude;
        this.longitude = longitude;
        this.icon = icon;
        this.tripId = tripId;
    }

    /** called by internal mechanisms, do not call yourself. */
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getStepDao() : null;
    }

    public Long getId() {
        return id;
    }

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

    public java.util.Date getDateFrom() {
        return dateFrom;
    }

    public void setDateFrom(java.util.Date dateFrom) {
        this.dateFrom = dateFrom;
    }

    public java.util.Date getDateTo() {
        return dateTo;
    }

    public void setDateTo(java.util.Date dateTo) {
        this.dateTo = dateTo;
    }

    public String getName() {
        return name;
    }

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

    public Double getLatitude() {
        return latitude;
    }

    public void setLatitude(Double latitude) {
        this.latitude = latitude;
    }

    public Double getLongitude() {
        return longitude;
    }

    public void setLongitude(Double longitude) {
        this.longitude = longitude;
    }

    public byte[] getIcon() {
        return icon;
    }

    public void setIcon(byte[] icon) {
        this.icon = icon;
    }

    public long getTripId() {
        return tripId;
    }

    public void setTripId(long tripId) {
        this.tripId = tripId;
    }

    /** To-one relationship, resolved on first access. */
    public Trip getTrip() {
        long __key = this.tripId;
        if (trip__resolvedKey == null || !trip__resolvedKey.equals(__key)) {
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            TripDao targetDao = daoSession.getTripDao();
            Trip tripNew = targetDao.load(__key);
            synchronized (this) {
                trip = tripNew;
            	trip__resolvedKey = __key;
            }
        }
        return trip;
    }

    public void setTrip(Trip trip) {
        if (trip == null) {
            throw new DaoException("To-one property 'tripId' has not-null constraint; cannot set to-one to null");
        }
        synchronized (this) {
            this.trip = trip;
            tripId = trip.getId();
            trip__resolvedKey = tripId;
        }
    }

    /** To-many relationship, resolved on first access (and after reset). Changes to to-many relations are not persisted, make changes to the target entity. */
    public List<Excursion> getExcursions() {
        if (excursions == null) {
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            ExcursionDao targetDao = daoSession.getExcursionDao();
            List<Excursion> excursionsNew = targetDao._queryStep_Excursions(id);
            synchronized (this) {
                if(excursions == null) {
                    excursions = excursionsNew;
                }
            }
        }
        return excursions;
    }

    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    public synchronized void resetExcursions() {
        excursions = null;
    }

    /** To-many relationship, resolved on first access (and after reset). Changes to to-many relations are not persisted, make changes to the target entity. */
    public List<Detail> getDetails() {
        if (details == null) {
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            DetailDao targetDao = daoSession.getDetailDao();
            List<Detail> detailsNew = targetDao._queryStep_Details(id);
            synchronized (this) {
                if(details == null) {
                    details = detailsNew;
                }
            }
        }
        return details;
    }

    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    public synchronized void resetDetails() {
        details = null;
    }

    /** Convenient call for {@link AbstractDao#delete(Object)}. Entity must attached to an entity context. */
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }    
        myDao.delete(this);
    }

    /** Convenient call for {@link AbstractDao#update(Object)}. Entity must attached to an entity context. */
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }    
        myDao.update(this);
    }

    /** Convenient call for {@link AbstractDao#refresh(Object)}. Entity must attached to an entity context. */
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }    
        myDao.refresh(this);
    }

}
