package ai.pai.lensman.bean;

import com.android.common.utils.JSONParseUtils;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;

public class GroupPhotoItem implements Serializable{

    public String photoName;
    public String photoId;
    public String captureTime;
    public String thumbnailUrl;
    public String bigThumbnailUrl;
    public String photoUrl;
    public String groupId;
    public short thumbnailWidth;
    public short thumbnailHeight;
    public String groupAvatar;
    public String uploaderId;
    public String groupName;
    public int groupDefaultAvatar;
    public String uploaderName;
    public String uploaderAvatar;
    public int commentNum;
    public int thumbupNum;
    public int groupFrom;
    public int photoFrom;
    public boolean thumbUp;

    public String mediumPhotoUrl;
    public String rawPhotoUrl;

    public String shareUrl;

    @Override
    public boolean equals(Object o) {
       if(o == this){
           return true;
       }
       if(!(o instanceof GroupPhotoItem)){
           return false;
       }
        GroupPhotoItem item = (GroupPhotoItem)o;
        return item.photoId.equals(photoId);
    }

    public static GroupPhotoItem parseFromJSON(JSONObject photoObj) throws JSONException{
        GroupPhotoItem item = new GroupPhotoItem();
        item.groupId= JSONParseUtils.getJSONString(photoObj.getString("group_id"));
        item.groupName = JSONParseUtils.getJSONString(photoObj.getString("group_name"));
        item.thumbnailWidth = (short)photoObj.getInt("photo_thumbnail_w");
        item.thumbnailHeight = (short)photoObj.getInt("photo_thumbnail_h");
        item.uploaderAvatar = JSONParseUtils.getJSONString(photoObj.getString("avatar"));
        item.commentNum = photoObj.getInt("comment_num");
        item.thumbupNum = photoObj.getInt("thumbup_num");
        item.groupAvatar = JSONParseUtils.getJSONString(photoObj.getString("group_avatar"));
        item.uploaderId = JSONParseUtils.getJSONString(photoObj.getString("user_id"));
        item.uploaderName = JSONParseUtils.getJSONString(photoObj.getString("nickname"));
        item.groupDefaultAvatar = photoObj.getInt("group_default_avatar");
        item.photoId= JSONParseUtils.getJSONString(photoObj.getString("photo_id"));
        item.photoUrl= JSONParseUtils.getJSONString(photoObj.getString("photo_url"));
        item.thumbnailUrl= JSONParseUtils.getJSONString(photoObj.getString("photo_thumbnail_url"));
        item.bigThumbnailUrl= JSONParseUtils.getJSONString(photoObj.getString("photo_thumbnail2_url"));
        item.captureTime = JSONParseUtils.getJSONString(photoObj.getString("created_at"));
        item.groupFrom = photoObj.getInt("group_from");
        item.photoFrom = photoObj.getInt("photo_from");
        item.thumbUp = photoObj.getBoolean("thumbup");
        if(photoObj.has("photo_share_url")){
            item.shareUrl = photoObj.getString("photo_share_url");
        }
        JSONObject pOrderObj = photoObj.getJSONObject("porder");
        if(pOrderObj.has("r_photo_url")){
            item.rawPhotoUrl = JSONParseUtils.getJSONString(pOrderObj.getString("r_photo_url"));
        }
        if(pOrderObj.has("m_photo_url")){
            item.mediumPhotoUrl = JSONParseUtils.getJSONString(pOrderObj.getString("m_photo_url"));
        }
        return item;
    }
}
