/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.activeblaze.wire;

import java.io.IOException;

/**
 * An Election
 */
public class Election extends Packet {
    public enum ElectionType {ELECTION, ANSWER, MASTER}

    ;
    private String memberId;
    private ElectionType electionType;

    public int getPacketType() {
        return PacketType.ELECTION.getNumber();
    }

    public Election clone() {
        Election result = new Election();
        copy(result);
        return result;
    }

    protected void copy(Election copy) {
        super.copy(copy);
        copy.memberId = this.memberId;
        copy.electionType = this.electionType;
    }

    /**
     * Get the memberId
     *
     * @return the memberId
     */
    public String getMemberId() {
        return this.memberId;
    }

    /**
     * Set the memberId
     *
     * @param memberId the memberId to set
     */
    public void setMemberId(String memberId) {
        this.memberId = memberId;
    }

    /**
     * Get the electionType
     *
     * @return the electionType
     */
    public ElectionType getElectionType() {
        return this.electionType;
    }

    /**
     * Set the electionType
     *
     * @param electionType the electionType to set
     */
    public void setElectionType(ElectionType electionType) {
        this.electionType = electionType;
    }

    public void read(BufferInputStream in) throws IOException {
        super.read(in);
        this.memberId = in.readString();
        this.electionType = ElectionType.valueOf(in.readString());
    }

    public void write(BufferOutputStream out) throws IOException {
        super.write(out);
        out.writeString(this.memberId);
        out.writeString(this.electionType.toString());
    }
}
