package uk.ac.starlink.ttools.taplint;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * Enumerates known ReportCode instances.
 * A short description is provided for each instance.
 * Note the description is not definitive, the actual message passed
 * through the reporting system in association with the code is the one
 * that should actually be passed to the user.
 *
 * <p>This class exists for taplint clients that want to have a static
 * idea of the ReportCode instances that may be reported by the taplint
 * framework.  Note it does <em>not</em> provide a complete list of
 * all the ReportCodes, since other ReportCode sublclasses may be used.
 * But it is expected to be the large majority.
 *
 * <p>The name of each enum element has a fixed form, <code>T_LLLL</code>,
 * where <code>T</code> is code.getType().getChar()
 *   and <code>LLLL</code> is code.getLabel().
 *
 * @author   Mark Taylor
 * @since    11 Jun 2014
 */
public enum FixedCode implements ReportCode {

    E_A2XI( "Non-ADQL2 declared as ADQL2" ),
    E_ADQX( "ADQL not declared" ),
    E_BAPH( "Incorrect starting phase" ),
    E_BMIM( "Illegal MIME type" ),
    E_CERR( "Error reading TAP_SCHEMA.columns data" ),
    E_CINT( "Wrong type for TAP_SCHEMA.columns column" ),
    E_CLDR( "Declared columns absent in result" ),
    E_CLIO( "Error reading TAP_SCHEMA.columns table" ),
    E_CLOG( "Non-boolean value" ),
    E_CLRD( "Unexpected columns in result" ),
    E_CNAM( "Query/result column name mismatch" ),
    E_CNID( "Column name not ADQL identifier" ),
    E_CPIF( "No TAP capability std interface declared" ),
    E_CPIO( "Capabilities metadata read error" ),
    E_CPSX( "Capabilities metadata parse failure" ),
    E_CPT1( "No unique TAP capability element" ),
    E_CPTV( "TAP version declaration mismatch" ),
    E_CRSV( "Column name ADQL reserved word" ),
    E_CTNO( "Continuation document not found" ),
    E_CTYP( "Declared/result type mismatch" ),
    E_CUCD( "UCD mismatch" ),
    E_CUNI( "Unit mismatch" ),
    E_CUTP( "Utype mismatch" ),
    E_DCER( "Document read error" ),
    E_DECO( "Non-303 response to job deletion" ),
    E_DEHT( "Bad HTTP job connection" ),
    E_DEMO( "Job deletion failure" ),
    E_DENO( "Non-404 response for deleted job" ),
    E_DEOP( "Unavailable job URL" ),
    E_DFIO( "Duff query failed" ),
    E_DFSF( "Duff query result parse failure" ),
    E_DNST( "Missing QUERY_STATUS from duff query" ),
    E_DQUM( "QUERY_STATUS inconsistency" ),
    E_DQUS( "Unknown value for QUERY_STATUS" ),
    E_DSUC( "Non-error return from duff query" ),
    E_ELDF( "Wrong top-level element" ),
    E_EST1( "Multiple QUERY_STATUS INFOs" ),
    E_EURL( "HTTP error" ),
    E_EXCH( "Bad continuation href attribute" ),
    E_EXDH( "Examples declaration/presence mismatch" ),
    E_EXCR( "Bad continuation resource attribute" ),
    E_EXIO( "Error reading examples document" ),
    E_EXPA( "Badly formed XML examples document" ),
    E_EXVC( "Incorrect examples RDFa vocab attribute" ),
    E_EXVP( "Unknown semantics term in RDFa property attribute" ),
    E_FKIO( "Error reading TAP_SCHEMA.keys table" ),
    E_FKLK( "Foreign key link broken" ),
    E_FKNT( "Foreign key target table absent" ),
    E_FLIO( "Table metadata read error" ),
    E_FLSX( "Table metadata parse failure" ),
    E_GEOX( "Unknown geometry function" ),
    E_GMIM( "Content-Type mismatch" ),
    E_GONM( "Missing mandatory resource" ),
    E_GPER( "Example generic-parameter markup wrong" ),
    E_HNUL( "Illegal NULLs in ObsCore column" ),
    E_HTDE( "HTTP DELETE failure" ),
    E_HTOF( "Unavailable job URL" ),
    E_IFMT( "Non-integer result" ),
    E_ILOP( "ObsCore value not in required set" ),
    E_ILPH( "Illegal job phase" ),
    E_IOER( "Error reading document" ),
    E_JBIO( "Job read error" ),
    E_JBSP( "Job parse error" ),
    E_JDDE( "Destruction time mismatch" ),
    E_JDED( "Execution duration mismatch" ),
    E_JDID( "Job ID mismatch" ),
    E_JDIO( "Error reading job document" ),
    E_JDNO( "Missing job document" ),
    E_JDPH( "Info/phase phase mismatch" ),
    E_JDSX( "Error parsing job document" ),
    E_JREJ( "Async job rejected before RUN" ),
    E_KCIO( "Error reading TAP_SCHEMA.key_columns table" ),
    E_KEYX( "Unknown standard language feature key" ),
    E_LVER( "Some ADQL variants fail" ),
    E_LNUL( "Illegal ObsPlan NULLs" ),
    E_LNSP( "Illegal ObsPlan NULL times" ),
    E_MCOL( "Query/result column count mismatch" ),
    E_MUPM( "Missing mandatory upload declaration" ),
    E_NAKT( "Table elements outside of any Schema" ),
    E_NFND( "Non-OK HTTP response" ),
    E_NO11( "Multi-cell result for COUNT" ),
    E_NOHT( "Non-HTTP job URL" ),
    E_NONM( "Non-numeric value for COUNT" ),
    E_NOOF( "No output formats defined" ),
    E_NOQL( "No query languages declared" ),
    E_NOST( "Missing QUERY_STATUS" ),
    E_NOVO( "Missing examples RDFa vocab attribute" ),
    E_NREC( "Maxrec limit exceeded" ),
    E_NRER( "COUNT error" ),
    E_NROW( "Row limit exceeded" ),
    E_OCOL( "Missing required ObsCore column" ),
    E_OVNO( "Overflow not signalled" ),
    E_PADU( "Duplicate parameter" ),
    E_PAMM( "Bad job parameter value" ),
    E_PANO( "Nameless parameter" ),
    E_PANZ( "Non-blank job parameter" ),
    E_PCOL( "Missing ObsLocTAP column" ),
    E_PCMS( "Incorrect obsplan column type" ),
    E_PHUR( "Incorrect phase" ),
    E_PLUT( "ObsLocTAP table wrong utype" ),
    E_PN0C( "Epn_core missing column" ),
    E_PN86( "Epn_core bad timestamp" ),
    E_PNDE( "Incorrect epn_core column type" ),
    E_PNDP( "Epn_core dataproduct_type bad values" ),
    E_PNFT( "Epn_core spatial_frame_type bad values" ),
    E_PNGT( "Epn_core geometry_type bad values" ),
    E_PNIK( "Bad InchiKey syntax" ),
    E_PNLT( "Epn_core local_time out of range" ),
    E_PNTN( "Epn_core table wrong name" ),
    E_PNMM( "Epn_core min/max constraints violated" ),
    E_PNMT( "Bad UCD in epn_core measurement_type" ),
    E_PNMX( "Epn_core min/max columns not paired" ),
    E_PNPL( "Illegal epn_core processing_level" ),
    E_PNST( "Service title not equal to schema" ),
    E_PNTG( "Illegal epn_core target_class" ),
    E_PNUL( "Illegal epn_core NULLs" ),
    E_PNUT( "Epn_core table wrong utype" ),
    E_PNMG( "Epn_core bad messenger" ),
    E_PNXT( "Wrong xtype for epn_core column" ),
    E_POER( "POST failure" ),
    E_PORE( "POST error" ),
    E_PPST( "Epn_core particle_spectral_type bad values" ),
    E_PTXT( "Non plain-text RDFa property content" ),
    E_PVAL( "Illegal ObsLocTAP cell value" ),
    E_QERR( "Query failed" ),
    E_QERX( "Query result parse error" ),
    E_QFAA( "Query failure" ),
    E_QST1( "Multiple pre-table QUERY_STATUS INFOs" ),
    E_QST2( "Multiple post-table QUERY_STATUS INFOs" ),
    E_RALC( "RDFa Lite rules violated" ),
    E_RANG( "ObsCore values out of range" ),
    E_RDPH( "Job phase read failure" ),
    E_RRES( "RESOURCE not marked 'results'" ),
    E_RRTO( "Row limit exceeded" ),
    E_RUPH( "Bad phase for started job" ),
    E_SCIO( "Error reading TAP_SCHEMA.schemas table" ),
    E_SPPA( "Spurious query parameter breaks query" ),
    E_SRXT( "Wrong xtype for s_region" ),
    E_SVRB( "Bad HTTP Server header syntax" ),
    E_TADH( "Tables endpoint declaration/presence mismatch" ),
    E_TAP0( "No TAP service found" ),
    E_TBIO( "Error reading TAP_SCHEMA.tables table" ),
    E_TMCD( "Upload result column value mismatch" ),
    E_TMCN( "Upload result column name mismatch" ),
    E_TMCX( "Upload result column xtype mismatch" ),
    E_TMNC( "Upload result column count mismatch" ),
    E_TMNR( "Upload result row count mismatch" ),
    E_TNTN( "Table name not ADQL table_name" ),
    E_TOVO( "Multiple examples RDFa vocab attributes" ),
    E_TRSV( "Table name ADQL reserved word" ),
    E_TSC0( "Missing TAP_SCHEMA column" ),
    E_TSCT( "Wrong type for TAP_SCHEMA column" ),
    E_TSAZ( "TAP_SCHEMA arraysize syntax error" ),
    E_TSSZ( "TAP_SCHEMA size/arraysize inconsistency" ),
    E_TST0( "Missing TAP_SCHEMA table" ),
    E_TSTD( "TAP_SCHEMA column not flagged Std" ),
    E_TSLN( "Missing TAP 1.1 TAP_SCHEMA foreign key" ),
    E_TSNL( "Null values in non-nullable column" ),
    E_TTOO( "Multiple result TABLEs" ),
    E_TYPX( "ObsCore datatype incompatibilty" ),
    E_UCDX( "Bad UCD" ),
    E_UDFE( "Bad UDF declaration" ),
    E_UKTB( "Unknown table referenced in example" ),
    E_UPBD( "Unknown upload suffix" ),
    E_UPER( "Upload error" ),
    E_VOCT( "Bad Content-Type for VOTable" ),
    E_VTIO( "Query result read error" ),
    E_VVLO( "VOTable version unsupported by TAP" ),
    E_XID0( "Missing id attribute on example" ),
    E_XOFK( "Unknown standard output format" ),
    E_XPRM( "Bad values for example parameters" ),
    E_XRS0( "Missing resource attribute on example" ),
    E_XRS1( "Resource/id attribute mismatch on example" ),

    W_A2MN( "No ADQL2 declaration" ),
    W_A2MX( "Non-standard ADQL2 declaration" ),
    W_AD2X( "ADQL2 not declared" ),
    W_CCAS( "Capitalisation mismatch" ),
    W_CDET( "Partial column metadata from /tables" ),
    W_CEUK( "Unknown Content-Encoding" ),
    W_CEZZ( "Compression" ),
    W_CIDX( "Index flag mismatch" ),
    W_CLUN( "Columns content" ),
    W_CPAN( "Deprecated declaration of anonymous resource" ),
    W_CPI2( "No unique std interface in capability" ),
    W_CPS2( "Duplicated security method ID" ),
    W_CPSM( "Unknown security method ID" ),
    W_CPUL( "Non-standard access URL for standard interface" ),
    W_CPUR( "Service and declared TAP base URL mismatch" ),
    W_CRGN( "Unknown DALI region xtype" ),
    W_CTYP( "Datatype possible mismatch" ),
    W_CUCD( "UCD mismatch" ),
    W_CUNI( "Unit mismatch" ),
    W_CUTP( "UType mismatch" ),
    W_DMDC( "DataModel not declared" ),
    W_DMSS( "DataModel subset undeclared" ),
    W_DRUC( "Declared/result UCD mismatch" ),
    W_DRUN( "Declared/result unit mismatch" ),
    W_DRUT( "Declared/result UType mismatch" ),
    W_DRXT( "Declared/result XType mismatch" ),
    W_DQU2( "Unknown value for post-table QUERY_STATUS" ),
    W_EX00( "No examples in examples document" ),
    W_EXUL( "Undeclared query language" ),
    W_EXVC( "Potentially problematic examples RDFa vocab attribute" ),
    W_EXVL( "Example query does not validate" ),
    W_EXVP( "Preliminary/deprecated semantics term in RDFa property att" ),
    W_FKUN( "Keys content" ),
    W_FLUN( "Key columns content" ),
    W_FTYP( "Foreign key type mismatch" ),
    W_GONO( "Missing optional resource" ),
    W_HSTB( "Non-duff return from duff query" ),
    W_HURL( "Redirect to non-HTTP URL" ),
    W_IODM( "Incorrect ObsCore ID" ),
    W_LVAN( "Language has empty version string" ),
    W_MLTR( "Multiple references to continuation document" ),
    W_NMID( "Id attribute is not XML Name" ),
    W_NOCT( "Missing Content-Type header" ),
    W_NOMS( "No error message text" ),
    W_NSOP( "ObsCore value not in suggested set" ),
    W_OLNG( "Bad LANG not rejected" ),
    W_PGEO( "Undeclared required geometry functions" ),
    W_PNJD( "Implausible Julian Day" ),
    W_PNMT( "Questionable UCD in epn_core measurement_type" ),
    W_PNTS( "Non-standard timescale" ),
    W_PNUB( "Transitional EPN-TAP utype" ),
    W_QERR( "Query failed" ),
    W_QTYP( "Query/result column type possible mismatch" ),
    W_RDIO( "Resource read error" ),
    W_SPPA( "Spurious query parameter changes result" ),
    W_SVR0( "No Server HTTP header" ),
    W_SVRV( "No VO components in Server HTTP header" ),
    W_SPUC( "Epn_core spatial UCD mismatch" ),
    W_SPUN( "Epn_core spatial unit mismatch" ),
    W_TADH( "Tables endpoint declaration/presence mismatch" ),
    W_TBNF( "Tables endpoint missing" ),
    W_TBUN( "Tables content" ),
    W_TFMT( "Non-ISO-8601 result" ),
    W_TSCT( "Questionable type for TAP_SCHEMA column" ),
    W_TSDL( "Bad time format in table data" ),
    W_TSZ1( "Single-element array declared" ),
    W_TYPI( "ObsCore datatype mismatch" ),
    W_UCDQ( "Questionable UCD" ),
    W_UNPH( "UNKNOWN phase" ),
    W_UNSC( "Foreign schema used in validation" ),
    W_UPCS( "Custom upload method" ),
    W_VUNE( "Unit is not legal VOUnit" ),
    W_VUNR( "Unit is not recommended VOUnit" ),
    W_VCPD( "Preliminary/deprecated vocabulary term" ),
    W_VUWS( "Unknown UWS version" ),
    W_WODM( "Incorrect ObsCore ID" ),
    W_ZRES( "Resolver not used?" ),

    F_CAIO( "Bad capabilities service URL" ),
    F_CAP0( "No capabilities available" ),
    F_CAPC( "XML parser error" ),
    F_DTIO( "Unexpected table read error" ),
    F_EXNO( "No examples document" ),
    F_EXRD( "Trouble reading example element" ),
    F_GONE( "Table metadata absent" ),
    F_INTR( "Interrupted" ),
    F_MURL( "Bad URL" ),
    F_NODT( "Metadata lacks column/key detail" ),
    F_NOPN( "No epn_core table" ),
    F_NOTB( "No obscore table" ),
    F_NOTM( "Earlier metadata stages not completed" ),
    F_NOTP( "No obsplan table" ),
    F_NOUP( "No upload methods listed" ),
    F_SXER( "Unexpected SAX parse error" ),
    F_TBLA( "Table has no name" ),
    F_TIOF( "Error reading result table" ),
    F_TRND( "Table randomisation failure" ),
    F_UNEX( "Unexpected error (validator bug?)" ),
    F_UTF8( "Unknown UTF8 encoding" ),
    F_XENT( "DTD entity trouble" ),
    F_XURL( "Bad document URL" ),
    F_XVAL( "Validator preparation error" ),
    F_ZCOL( "No columns known for tests" ),

    I_CDET( "No column metadata from /tables" ),
    I_CJOB( "Job created" ),
    I_CULF( "Custom language feature type" ),
    I_CURL( "Reading capability metadata" ),
    I_DMID( "Data model declared" ),
    I_DQUR( "QUERY_STATUS redundancy" ),
    I_DUFF( "Duff query" ),
    I_EURL( "Reading examples document" ),
    I_EXA2( "Assume default query language" ),
    I_EXMP( "Example found" ),
    I_EXVT( "Possible issues with examples RDFa vocab attribute" ),
    I_JOFI( "Job finished immediately" ),
    I_NODM( "No ObsCore tests" ),
    I_OCCP( "No ObsCore tests" ),
    I_PNIX( "Starting epn_core tests" ),
    I_PNSP( "Checking spatial-frame-specific coord metadata" ),
    I_PNNS( "Non-standard epn_core columns" ),
    I_POPA( "Job POSTed" ),
    I_QGET( "Query GET URL" ),
    I_QJOB( "Submitted query URL" ),
    I_QSUB( "Submitted query" ),
    I_SCHM( "Use TAP_SCHEMA for metadata" ),
    I_SVRI( "HTTP Server header value" ),
    I_TAPV( "TAP validation version" ),
    I_TMAX( "Table test count" ),
    I_TSNS( "Non-standard TAP_SCHEMA columns" ),
    I_TURL( "Reading table metadata" ),
    I_UCDV( "UCD library/standard version" ),
    I_VURL( "Validation" ),
    I_VUWS( "UWS job document version" ),
    I_VVNL( "Undeclared VOTable version" ),
    I_VVUN( "Unknown VOTable version" ),

    S_COLS( "ObsCore columns" ),
    S_FILT( "Filter selected tables" ),
    S_FLGO( "Non-standard column flags" ),
    S_FLGS( "Standard column flags" ),
    S_PCLS( "ObsLocTAP columns" ),
    S_PNCS( "EPN-TAP columns" ),
    S_PNCN( "Epn_core table count" ),
    S_QNUM( "Query count" ),
    S_QTIM( "Query time" ),
    S_SUMM( "Table metadata" ),
    S_VALI( "Validation" ),
    S_XNUM( "Example count summary" ),
    S_XVAL( "Example validation summary" );

    private final String description_;

    /**
     * Constructor.
     *
     * @param  description  short description
     */
    FixedCode( String description ) {
        description_ = description;
    }

    public ReportType getType() {
        return ReportType.forChar( name().charAt( 0 ) );
    }

    public String getLabel() {
        return name().substring( 2 );
    }

    /**
     * Returns a short textual description of the use of this code.
     * It may not be very precise; if the message put through the reporting
     * system is available, that should be used in preference.
     *
     * @return  description
     */
    public String getDescription() {
        return description_;
    }
}
