package com.raizlabs.android.databasecomparison.greendao.gen;

import java.util.Collection;
import java.util.List;

import com.raizlabs.android.databasecomparison.interfaces.IAddressBook;

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 ADDRESS_BOOK.
 */
public class AddressBook implements IAddressBook<AddressItem, Contact> {

    private Long id;
    private String name;
    private String author;

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

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

    protected Collection<AddressItem> addressItemList;
    protected Collection<Contact> contactList;

    public AddressBook() {
    }

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

    public AddressBook(Long id, String name, String author) {
        this.id = id;
        this.name = name;
        this.author = author;
    }

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

    public Long getId() {
        return id;
    }

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

    public String getName() {
        return name;
    }

    @Override
    public void setId(long id) {
        this.id = id;
    }

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

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    @Override
    public void setAddresses(Collection<AddressItem> addresses) {
        addressItemList = addresses;
    }

    @Override
    public Collection<AddressItem> getAddresses() {
        return addressItemList;
    }

    @Override
    public Collection<Contact> getContacts() {
        return contactList;
    }

    @Override
    public void setContacts(Collection<Contact> contacts) {
        contactList = contacts;
    }

    /** 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 Collection<AddressItem> getAddressItemList() {
        if (addressItemList == null) {
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            AddressItemDao targetDao = daoSession.getAddressItemDao();
            List<AddressItem> addressItemListNew = targetDao._queryAddressBook_AddressItemList(id);
            synchronized (this) {
                if(addressItemList == null) {
                    addressItemList = addressItemListNew;
                }
            }
        }
        return addressItemList;
    }

    public void setAddressItemList(List<AddressItem> addressItemList) {
        this.addressItemList = addressItemList;
    }

    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    public synchronized void resetAddressItemList() {
        addressItemList = 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 Collection<Contact> getContactList() {
        if (contactList == null) {
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            ContactDao targetDao = daoSession.getContactDao();
            List<Contact> contactListNew = targetDao._queryAddressBook_ContactList(id);
            synchronized (this) {
                if(contactList == null) {
                    contactList = contactListNew;
                }
            }
        }
        return contactList;
    }

    public void setContactList(List<Contact> contactList) {
        this.contactList = contactList;
    }

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

    @Override
    public void saveAll() {

    }
}