package org.grobid.core.data;

/**
 * Class for managing patent bibliographical references.
 *
 * @author Patrice Lopez
 */
public class PatentItem implements Comparable {
    // attribute
    private String authority = null;
    private String number = null;
    private String kindCode = null;

    // patent type when applicable
    private Boolean application = false;
    private Boolean provisional = false;
    private Boolean reissued = false;
    private Boolean plant = false;
    private Boolean design = false;

    // scores
    private double conf = 0.0;
    private String confidence = null;

    // position in document
    private int offset_begin = 0;
    private int offset_end = 0;

    // position in raw string (in case of factorised numbers)
    private int offset_raw = 0;

    // context of occurrence of the reference
    private String context = null;

    public String getAuthority() {
        return authority;
    }

    public String getNumber() {
        return number;
    }

    public String getKindCode() {
        return kindCode;
    }

    public Boolean getApplication() {
        return application;
    }

    public Boolean getProvisional() {
        return provisional;
    }

    public Boolean getReissued() {
        return reissued;
    }

    public Boolean getPlant() {
        return plant;
    }

    public Boolean getDesign() {
        return design;
    }

    public double getConf() {
        return conf;
    }

    public String getConfidence() {
        return confidence;
    }

    public int getOffsetBegin() {
        return offset_begin;
    }

    public int getOffsetEnd() {
        return offset_end;
    }

    public int getOffsetRaw() {
        return offset_raw;
    }

    /**
     * Context of occurrence of the reference
     */
    public String getContext() {
        return context;
    }

    public void setContext(String cont) {
        context = cont;
    }

    public void setOffsetBegin(int ofs) {
        offset_begin = ofs;
    }

    public void setOffsetEnd(int ofs) {
        offset_end = ofs;
    }

    public void setOffsetRaw(int ofs) {
        offset_raw = ofs;
    }

    public void setKindCode(String kc) {
        kindCode = kc;
    }

    public void setNumber(String num) {
        number = num;
    }

    public void setAuthority(String s) {
        authority = s;
    }

    public void setApplication(boolean b) {
        application = b;
    }

    public void setProvisional(boolean b) {
        provisional = b;
    }

    public void setReissued(boolean b) {
        reissued = b;
    }

    public void setPlant(boolean b) {
        plant = b;
    }

    public void setDesign(boolean b) {
        design = b;
    }

    public int compareTo(Object another) {
        return number.compareTo(((PatentItem) another).getNumber());
    }

    private final static String espacenet = "http://v3.espacenet.com/publicationDetails/biblio?DB=EPODOC";
    private final static String espacenet2 = "http://v3.espacenet.com/searchResults?DB=EPODOC";

    private final static String epoline = "https://register.epoline.org/espacenet/application?number=";

    private final static String epoline2 = "https://register.epoline.org/espacenet/simpleSearch?index[0]=publication&value[0]=";
    private final static String epoline3 = "&index[1]=&value[1]=&index[2]=&value[2]=&searchMode=simple&recent=";

    public String getEspacenetURL() {
        String res = null;
        if (provisional) {
            res = espacenet2 + "&PR=" + authority + number + "P";
        } else if (application) {
            res = espacenet2 + "&AP=" + authority + number;
        } else {
            res = espacenet + "&CC=" + authority + "&NR=" + number;
        }
        return res;
    }

    public String getEpolineURL() {
        String res = null;
        if (application) {
            res = epoline + authority + number;
        } else {
            // we need the application number corresponding to the publication
            res = epoline2 + authority + number + epoline3;
        }
        return res;
    }

    public String getType() {
        if (application)
            return "application";
        if (provisional)
            return "provisional";
        if (reissued)
            return "reissued";
        if (plant)
            return "plant";
        if (design)
            return "design";
        // default
        return "publication";
    }

    public void setType(String type) {
        if (type.equals("publication"))
            return;
        if (type.equals("application")) {
            application = true;
        } else if (type.equals("provisional")) {
            provisional = true;
        } else if (type.equals("reissued")) {
            reissued = true;
        } else if (type.equals("plant")) {
            plant = true;
        } else if (type.equals("design")) {
            design = true;
        }
    }
}
@@ -162,19 +162,31 @@
 mparable
+%3CPatentItem%3E
  %7B%0A
-
     // a
@@ -2762,14 +2762,18 @@
 eTo(
-Object
+PatentItem
  ano
@@ -2816,30 +2816,15 @@
 eTo(
-((PatentItem) 
 another
-)
 .get
@@ -4930,15 +4930,504 @@
       %7D%0A
-
     %7D
+%0A%0A%09@Override%0A%09public String toString() %7B%0A%09%09return %22PatentItem %5Bauthority=%22 + authority + %22, number=%22 + number%0A%09%09%09%09+ %22, kindCode=%22 + kindCode + %22, application=%22 + application%0A%09%09%09%09+ %22, provisional=%22 + provisional + %22, reissued=%22 + reissued%0A%09%09%09%09+ %22, plant=%22 + plant + %22, design=%22 + design + %22, conf=%22 + conf%0A%09%09%09%09+ %22, confidence=%22 + confidence + %22, offset_begin=%22%0A%09%09%09%09+ offset_begin + %22, offset_end=%22 + offset_end + %22, offset_raw=%22%0A%09%09%09%09+ offset_raw + %22, context=%22 + context + %22%5D%22;%0A%09%7D%0A    %0A    
 %0A%7D

Add toString method.