/**
 * 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.Collections;
import java.util.HashMap;
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.protocol.TField;
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 Phone implements TBase, java.io.Serializable, Cloneable {
    private static final TStruct STRUCT_DESC = new TStruct("Phone");
    private static final TField ID_FIELD_DESC = new TField("id", TType.I32, (short) 1);
    private static final TField NUMBER_FIELD_DESC = new TField("number", TType.STRING, (short) 2);
    private static final TField TYPE_FIELD_DESC = new TField("type", TType.STRING, (short) 3);

    public int id;
    public static final int ID = 1;
    public String number;
    public static final int NUMBER = 2;
    public String type;
    public static final int TYPE = 3;

    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(NUMBER, new FieldMetaData("number", TFieldRequirementType.DEFAULT, new FieldValueMetaData(
                            TType.STRING)));
                    put(TYPE, new FieldMetaData("type", TFieldRequirementType.DEFAULT, new FieldValueMetaData(
                            TType.STRING)));
                }
            });

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

    public Phone() {
    }

    public Phone(int id, String number, String type) {
        this();
        this.id = id;
        this.__isset.id = true;
        this.number = number;
        this.type = type;
    }

    /**
     * Performs a deep copy on <i>other</i>.
     */
    public Phone(Phone other) {
        __isset.id = other.__isset.id;
        this.id = other.id;
        if (other.isSetNumber()) {
            this.number = other.number;
        }
        if (other.isSetType()) {
            this.type = other.type;
        }
    }

    @Override
    public Phone clone() {
        return new Phone(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 getNumber() {
        return this.number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public void unsetNumber() {
        this.number = null;
    }

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

    public void setNumberIsSet(boolean value) {
        if (!value) {
            this.number = null;
        }
    }

    public String getType() {
        return this.type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public void unsetType() {
        this.type = null;
    }

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

    public void setTypeIsSet(boolean value) {
        if (!value) {
            this.type = null;
        }
    }

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

        case NUMBER:
            if (value == null) {
                unsetNumber();
            } else {
                setNumber((String) value);
            }
            break;

        case TYPE:
            if (value == null) {
                unsetType();
            } else {
                setType((String) 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 NUMBER:
            return getNumber();

        case TYPE:
            return getType();

        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 NUMBER:
            return isSetNumber();
        case TYPE:
            return isSetType();
        default:
            throw new IllegalArgumentException("Field " + fieldID + " doesn't exist!");
        }
    }

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

    public boolean equals(Phone 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_number = true && this.isSetNumber();
        boolean that_present_number = true && that.isSetNumber();
        if (this_present_number || that_present_number) {
            if (!(this_present_number && that_present_number))
                return false;
            if (!this.number.equals(that.number))
                return false;
        }

        boolean this_present_type = true && this.isSetType();
        boolean that_present_type = true && that.isSetType();
        if (this_present_type || that_present_type) {
            if (!(this_present_type && that_present_type))
                return false;
            if (!this.type.equals(that.type))
                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 NUMBER:
                if (field.type == TType.STRING) {
                    this.number = iprot.readString();
                } else {
                    TProtocolUtil.skip(iprot, field.type);
                }
                break;
            case TYPE:
                if (field.type == TType.STRING) {
                    this.type = iprot.readString();
                } 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.number != null) {
            oprot.writeFieldBegin(NUMBER_FIELD_DESC);
            oprot.writeString(this.number);
            oprot.writeFieldEnd();
        }
        if (this.type != null) {
            oprot.writeFieldBegin(TYPE_FIELD_DESC);
            oprot.writeString(this.type);
            oprot.writeFieldEnd();
        }
        oprot.writeFieldStop();
        oprot.writeStructEnd();
    }

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

        sb.append("id:");
        sb.append(this.id);
        first = false;
        if (!first)
            sb.append(", ");
        sb.append("number:");
        if (this.number == null) {
            sb.append("null");
        } else {
            sb.append(this.number);
        }
        first = false;
        if (!first)
            sb.append(", ");
        sb.append("type:");
        if (this.type == null) {
            sb.append("null");
        } else {
            sb.append(this.type);
        }
        first = false;
        sb.append(")");
        return sb.toString();
    }

    public void validate() throws TException {
        //It would be better if this did not have to be added by hand.
        // :(
        if (!"HOME".equals(type) && !"WORK".equals(type) &&
            !"MOBILE".equals(type) && !"OTHER".equals(type)) {
            throw new TException("Unknown Phone Type " + type);
        }
    }
}
