/**
 * Autogenerated by Thrift
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 */
package com.ociweb.jnb.thrift.gen;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.thrift.TBase;
import org.apache.thrift.TException;
import org.apache.thrift.TFieldRequirementType;
import org.apache.thrift.meta_data.FieldMetaData;
import org.apache.thrift.meta_data.FieldValueMetaData;
import org.apache.thrift.meta_data.ListMetaData;
import org.apache.thrift.meta_data.StructMetaData;
import org.apache.thrift.protocol.TField;
import org.apache.thrift.protocol.TList;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.protocol.TProtocolUtil;
import org.apache.thrift.protocol.TStruct;
import org.apache.thrift.protocol.TType;

@SuppressWarnings("serial")
public class Person implements TBase, java.io.Serializable, Cloneable {
    private static final TStruct STRUCT_DESC = new TStruct("Person");
    private static final TField ID_FIELD_DESC = new TField("id", TType.I32, (short) 1);
    private static final TField FIRST_NAME_FIELD_DESC = new TField("firstName", TType.STRING, (short) 2);
    private static final TField LAST_NAME_FIELD_DESC = new TField("lastName", TType.STRING, (short) 3);
    private static final TField EMAIL_FIELD_DESC = new TField("email", TType.STRING, (short) 4);
    private static final TField PHONES_FIELD_DESC = new TField("phones", TType.LIST, (short) 5);

    public int id;
    public static final int ID = 1;
    public String firstName;
    public static final int FIRSTNAME = 2;
    public String lastName;
    public static final int LASTNAME = 3;
    public String email;
    public static final int EMAIL = 4;
    public List<Phone> phones;
    public static final int PHONES = 5;

    private final Isset __isset = new Isset();

    private static final class Isset implements java.io.Serializable {
        public boolean id = false;
    }

    public static final Map<Integer, FieldMetaData> metaDataMap = Collections
            .unmodifiableMap(new HashMap<Integer, FieldMetaData>() {
                {
                    put(ID, new FieldMetaData("id", TFieldRequirementType.DEFAULT, new FieldValueMetaData(TType.I32)));
                    put(FIRSTNAME, new FieldMetaData("firstName", TFieldRequirementType.DEFAULT,
                            new FieldValueMetaData(TType.STRING)));
                    put(LASTNAME, new FieldMetaData("lastName", TFieldRequirementType.DEFAULT, new FieldValueMetaData(
                            TType.STRING)));
                    put(EMAIL, new FieldMetaData("email", TFieldRequirementType.DEFAULT, new FieldValueMetaData(
                            TType.STRING)));
                    put(PHONES, new FieldMetaData("phones", TFieldRequirementType.DEFAULT, new ListMetaData(TType.LIST,
                            new StructMetaData(TType.STRUCT, Phone.class))));
                }
            });

    static {
        FieldMetaData.addStructMetaDataMap(Person.class, metaDataMap);
    }

    public Person() {
    }

    public Person(int id, String firstName, String lastName, String email, List<Phone> phones) {
        this();
        this.id = id;
        this.__isset.id = true;
        this.firstName = firstName;
        this.lastName = lastName;
        this.email = email;
        this.phones = phones;
    }

    /**
     * Performs a deep copy on <i>other</i>.
     */
    public Person(Person other) {
        __isset.id = other.__isset.id;
        this.id = other.id;
        if (other.isSetFirstName()) {
            this.firstName = other.firstName;
        }
        if (other.isSetLastName()) {
            this.lastName = other.lastName;
        }
        if (other.isSetEmail()) {
            this.email = other.email;
        }
        if (other.isSetPhones()) {
            List<Phone> __this__phones = new ArrayList<Phone>();
            for (Phone other_element : other.phones) {
                __this__phones.add(new Phone(other_element));
            }
            this.phones = __this__phones;
        }
    }

    @Override
    public Person clone() {
        return new Person(this);
    }

    public int getId() {
        return this.id;
    }

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

    public void unsetId() {
        this.__isset.id = false;
    }

    // Returns true if field id is set (has been asigned a value) and false
    // otherwise
    public boolean isSetId() {
        return this.__isset.id;
    }

    public void setIdIsSet(boolean value) {
        this.__isset.id = value;
    }

    public String getFirstName() {
        return this.firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public void unsetFirstName() {
        this.firstName = null;
    }

    // Returns true if field firstName is set (has been asigned a value) and
    // false otherwise
    public boolean isSetFirstName() {
        return this.firstName != null;
    }

    public void setFirstNameIsSet(boolean value) {
        if (!value) {
            this.firstName = null;
        }
    }

    public String getLastName() {
        return this.lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public void unsetLastName() {
        this.lastName = null;
    }

    // Returns true if field lastName is set (has been asigned a value) and
    // false otherwise
    public boolean isSetLastName() {
        return this.lastName != null;
    }

    public void setLastNameIsSet(boolean value) {
        if (!value) {
            this.lastName = null;
        }
    }

    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public void unsetEmail() {
        this.email = null;
    }

    // Returns true if field email is set (has been asigned a value) and false
    // otherwise
    public boolean isSetEmail() {
        return this.email != null;
    }

    public void setEmailIsSet(boolean value) {
        if (!value) {
            this.email = null;
        }
    }

    public int getPhonesSize() {
        return (this.phones == null) ? 0 : this.phones.size();
    }

    public java.util.Iterator<Phone> getPhonesIterator() {
        return (this.phones == null) ? null : this.phones.iterator();
    }

    public void addToPhones(Phone elem) {
        if (this.phones == null) {
            this.phones = new ArrayList<Phone>();
        }
        this.phones.add(elem);
    }

    public List<Phone> getPhones() {
        return this.phones;
    }

    public void setPhones(List<Phone> phones) {
        this.phones = phones;
    }

    public void unsetPhones() {
        this.phones = null;
    }

    // Returns true if field phones is set (has been asigned a value) and false
    // otherwise
    public boolean isSetPhones() {
        return this.phones != null;
    }

    public void setPhonesIsSet(boolean value) {
        if (!value) {
            this.phones = null;
        }
    }

    @SuppressWarnings("unchecked")
    public void setFieldValue(int fieldID, Object value) {
        switch (fieldID) {
        case ID:
            if (value == null) {
                unsetId();
            } else {
                setId((Integer) value);
            }
            break;

        case FIRSTNAME:
            if (value == null) {
                unsetFirstName();
            } else {
                setFirstName((String) value);
            }
            break;

        case LASTNAME:
            if (value == null) {
                unsetLastName();
            } else {
                setLastName((String) value);
            }
            break;

        case EMAIL:
            if (value == null) {
                unsetEmail();
            } else {
                setEmail((String) value);
            }
            break;

        case PHONES:
            if (value == null) {
                unsetPhones();
            } else {
                setPhones((List<Phone>) value);
            }
            break;

        default:
            throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!");
        }
    }

    public Object getFieldValue(int fieldID) {
        switch (fieldID) {
        case ID:
            return new Integer(getId());

        case FIRSTNAME:
            return getFirstName();

        case LASTNAME:
            return getLastName();

        case EMAIL:
            return getEmail();

        case PHONES:
            return getPhones();

        default:
            throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!");
        }
    }

    // Returns true if field corresponding to fieldID is set (has been asigned a
    // value) and false otherwise
    public boolean isSet(int fieldID) {
        switch (fieldID) {
        case ID:
            return isSetId();
        case FIRSTNAME:
            return isSetFirstName();
        case LASTNAME:
            return isSetLastName();
        case EMAIL:
            return isSetEmail();
        case PHONES:
            return isSetPhones();
        default:
            throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!");
        }
    }

    @Override
    public boolean equals(Object that) {
        if (that == null)
            return false;
        if (that instanceof Person)
            return this.equals((Person) that);
        return false;
    }

    public boolean equals(Person that) {
        if (that == null)
            return false;

        boolean this_present_id = true;
        boolean that_present_id = true;
        if (this_present_id || that_present_id) {
            if (!(this_present_id && that_present_id))
                return false;
            if (this.id != that.id)
                return false;
        }

        boolean this_present_firstName = true && this.isSetFirstName();
        boolean that_present_firstName = true && that.isSetFirstName();
        if (this_present_firstName || that_present_firstName) {
            if (!(this_present_firstName && that_present_firstName))
                return false;
            if (!this.firstName.equals(that.firstName))
                return false;
        }

        boolean this_present_lastName = true && this.isSetLastName();
        boolean that_present_lastName = true && that.isSetLastName();
        if (this_present_lastName || that_present_lastName) {
            if (!(this_present_lastName && that_present_lastName))
                return false;
            if (!this.lastName.equals(that.lastName))
                return false;
        }

        boolean this_present_email = true && this.isSetEmail();
        boolean that_present_email = true && that.isSetEmail();
        if (this_present_email || that_present_email) {
            if (!(this_present_email && that_present_email))
                return false;
            if (!this.email.equals(that.email))
                return false;
        }

        boolean this_present_phones = true && this.isSetPhones();
        boolean that_present_phones = true && that.isSetPhones();
        if (this_present_phones || that_present_phones) {
            if (!(this_present_phones && that_present_phones))
                return false;
            if (!this.phones.equals(that.phones))
                return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        return 0;
    }

    public void read(TProtocol iprot) throws TException {
        TField field;
        iprot.readStructBegin();
        while (true) {
            field = iprot.readFieldBegin();
            if (field.type == TType.STOP) {
                break;
            }
            switch (field.id) {
            case ID:
                if (field.type == TType.I32) {
                    this.id = iprot.readI32();
                    this.__isset.id = true;
                } else {
                    TProtocolUtil.skip(iprot, field.type);
                }
                break;
            case FIRSTNAME:
                if (field.type == TType.STRING) {
                    this.firstName = iprot.readString();
                } else {
                    TProtocolUtil.skip(iprot, field.type);
                }
                break;
            case LASTNAME:
                if (field.type == TType.STRING) {
                    this.lastName = iprot.readString();
                } else {
                    TProtocolUtil.skip(iprot, field.type);
                }
                break;
            case EMAIL:
                if (field.type == TType.STRING) {
                    this.email = iprot.readString();
                } else {
                    TProtocolUtil.skip(iprot, field.type);
                }
                break;
            case PHONES:
                if (field.type == TType.LIST) {
                    {
                        TList _list0 = iprot.readListBegin();
                        this.phones = new ArrayList<Phone>(_list0.size);
                        for (int _i1 = 0; _i1 < _list0.size; ++_i1) {
                            Phone _elem2;
                            _elem2 = new Phone();
                            _elem2.read(iprot);
                            this.phones.add(_elem2);
                        }
                        iprot.readListEnd();
                    }
                } else {
                    TProtocolUtil.skip(iprot, field.type);
                }
                break;
            default:
                TProtocolUtil.skip(iprot, field.type);
                break;
            }
            iprot.readFieldEnd();
        }
        iprot.readStructEnd();

        // check for required fields of primitive type, which can't be checked
        // in the validate method
        validate();
    }

    public void write(TProtocol oprot) throws TException {
        validate();

        oprot.writeStructBegin(STRUCT_DESC);
        oprot.writeFieldBegin(ID_FIELD_DESC);
        oprot.writeI32(this.id);
        oprot.writeFieldEnd();
        if (this.firstName != null) {
            oprot.writeFieldBegin(FIRST_NAME_FIELD_DESC);
            oprot.writeString(this.firstName);
            oprot.writeFieldEnd();
        }
        if (this.lastName != null) {
            oprot.writeFieldBegin(LAST_NAME_FIELD_DESC);
            oprot.writeString(this.lastName);
            oprot.writeFieldEnd();
        }
        if (this.email != null) {
            oprot.writeFieldBegin(EMAIL_FIELD_DESC);
            oprot.writeString(this.email);
            oprot.writeFieldEnd();
        }
        if (this.phones != null) {
            oprot.writeFieldBegin(PHONES_FIELD_DESC);
            {
                oprot.writeListBegin(new TList(TType.STRUCT, this.phones.size()));
                for (Phone _iter3 : this.phones) {
                    _iter3.write(oprot);
                }
                oprot.writeListEnd();
            }
            oprot.writeFieldEnd();
        }
        oprot.writeFieldStop();
        oprot.writeStructEnd();
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("Person(");
        boolean first = true;

        sb.append("id:");
        sb.append(this.id);
        first = false;
        if (!first)
            sb.append(", ");
        sb.append("firstName:");
        if (this.firstName == null) {
            sb.append("null");
        } else {
            sb.append(this.firstName);
        }
        first = false;
        if (!first)
            sb.append(", ");
        sb.append("lastName:");
        if (this.lastName == null) {
            sb.append("null");
        } else {
            sb.append(this.lastName);
        }
        first = false;
        if (!first)
            sb.append(", ");
        sb.append("email:");
        if (this.email == null) {
            sb.append("null");
        } else {
            sb.append(this.email);
        }
        first = false;
        if (!first)
            sb.append(", ");
        sb.append("phones:");
        if (this.phones == null) {
            sb.append("null");
        } else {
            sb.append(this.phones);
        }
        first = false;
        sb.append(")");
        return sb.toString();
    }

    public void validate() throws TException {
        // check for required fields
        // check that fields of type enum have valid values
    }

}
