package motoSample;

import java.io.Serializable;

import java.util.logging.Logger;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.PreparedStatement;

import java.util.ArrayList;


public class MemberList extends ArrayList<MemberList.ChatMember> {

    private static Logger log = Logger.getLogger(MemberList.class.getName());
    private LoginMemberBean loginMembers;
    
    
    private String chatRoom;

    public void setChatRoom(String chatRoom) {
        this.chatRoom = chatRoom;
    }
    public String getChatRoom() {
        return chatRoom;
    }
    public void setLoginMember(LoginMemberBean loginMembers) {
        this.loginMembers = loginMembers;
    }
    

    ///chat list data
    public static class ChatMember {
        private String uname;
        private boolean isLogin;

        public String getUname() {
            return uname;
        }
        public void setUname(String uname) {
            this.uname = uname;
        }
        public boolean getIsLogin() {
            return isLogin;
        }
        public void setIsLogin(boolean isLogin) {
            this.isLogin = isLogin;
        }
    }

	public void initMemList(){
        log.info("initMemList: ");
	    this.clear();
        try {
            Connection conn = Resources.getConnection();
            String sqlString = "select user_id from tb_user_flights where flight_name=\'" + chatRoom +"\'";
            //log.info("sqlString: " + sqlString);

            Statement statement = conn.createStatement();
            ResultSet rs = statement.executeQuery(sqlString);
            
            while (rs.next()) {
                ChatMember m = new ChatMember();
                m.uname = rs.getString("user_id");
                m.isLogin = loginMembers.isLogin(m.uname);
                this.add(m);
            }
            
            rs.close();
            conn.close();
        }
        catch (SQLException se) {
            log.severe("sql err!!!");
        }

	}

}
