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 DAY.
 */
public class Day {

    private Long id;
    private java.util.Date day;
    private long tripId;
    private Integer park;

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

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

    private Trip trip;
    private Long trip__resolvedKey;

    private List<Service> services;

    public Day() {
    }

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

    public Day(Long id, java.util.Date day, long tripId, Integer park) {
        this.id = id;
        this.day = day;
        this.tripId = tripId;
        this.park = park;
    }

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

    public Long getId() {
        return id;
    }

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

    public java.util.Date getDay() {
        return day;
    }

    public void setDay(java.util.Date day) {
        this.day = day;
    }

    public long getTripId() {
        return tripId;
    }

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

    public Integer getPark() {
        return park;
    }

    public void setPark(Integer park) {
        this.park = park;
    }

    /** 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<Service> getServices() {
        if (services == null) {
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            ServiceDao targetDao = daoSession.getServiceDao();
            List<Service> servicesNew = targetDao._queryDay_Services(id);
            synchronized (this) {
                if(services == null) {
                    services = servicesNew;
                }
            }
        }
        return services;
    }

    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    public synchronized void resetServices() {
        services = 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);
    }

}
