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 HERITAGE.
 */
public class Heritage {

    private Long id;
    private String name;
    private byte[] icon;

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

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

    private List<Detail> details;
    private List<DbPolygon> polygons;

    public Heritage() {
    }

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

    public Heritage(Long id, String name, byte[] icon) {
        this.id = id;
        this.name = name;
        this.icon = icon;
    }

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

    public Long getId() {
        return id;
    }

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

    public String getName() {
        return name;
    }

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

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

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

    /** 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._queryHeritage_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;
    }

    /** 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<DbPolygon> getPolygons() {
        if (polygons == null) {
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            DbPolygonDao targetDao = daoSession.getDbPolygonDao();
            List<DbPolygon> polygonsNew = targetDao._queryHeritage_Polygons(id);
            synchronized (this) {
                if(polygons == null) {
                    polygons = polygonsNew;
                }
            }
        }
        return polygons;
    }

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

}
