package ctbrec.ui.sites.stripchat;

import ctbrec.StringUtil;
import ctbrec.ui.tabs.PaginatedScheduledService;
import org.json.JSONObject;

import java.text.MessageFormat;

public abstract class AbstractStripchatUpdateService extends PaginatedScheduledService {

    protected String getPreviewUrl(JSONObject model) {
        try {
            long id = model.getLong("id");
            long timestamp = model.getLong("snapshotTimestamp");
            String snapshotServer = model.getString("snapshotServer");
            if (timestamp == 0 || StringUtil.isBlank(snapshotServer)) {
                throw new IllegalStateException("Model seems to be offline");
            }
            return MessageFormat.format("https://img.strpst.com/thumbs/{0}/{1}_jpg", String.valueOf(timestamp), String.valueOf(id));
        } catch (Exception e) {
            return model.optString("previewUrlThumbBig");
        }
    }
}
