import "wmconsole/version3/protos/common.proto";

package NWebmaster.proto.sitemap;
option java_package = "ru.yandex.webmaster3.proto";

message SitemapMessage {
    required ApplicationInfo application_info = 1;
    required MessageInfo message_info         = 2;

    repeated SitemapInfo sitemaps             = 100;
}

message SitemapInfoTimestamps {
    optional int64 http_code_timestamp          = 1;
    optional int64 last_access_timestamp        = 2;
    optional int64 source_id_timestamp          = 3;
    optional int64 redir_target_timestamp       = 4;
    optional int64 urls_timestamp               = 5;
    optional int64 errors_timestamp             = 6;
    optional int64 is_sitemap_parsed_timestamp  = 7;
    optional int64 is_index_timestamp           = 8;
}

message SitemapInfo {
    required SitemapType type                   = 1;
    optional string sitemap_url                 = 2;

    optional int32 http_code                    = 3;
    optional uint32 last_access                 = 4; //seconds since epoch
    optional uint32 url_count                   = 5;
    optional uint32 error_count                 = 6;
    optional UrlSourceId source_id              = 7;
    optional string redir_target                = 8;
    optional bool is_sitemap_parsed             = 9;

    optional SitemapInfoTimestamps timestamps   = 10;
    optional SitemapTypeEx type_ex              = 11;

    repeated string urls                        = 20;
    repeated SitemapError errors                = 30;
}

message LemurSitemapExportTimestamps {
    optional int64 last_change_time_timestamp   = 1;
    optional int64 related_sitemaps_timestamp   = 2;
}

message LemurSitemapExportMessage {
    repeated SitemapInfo sitemaps                           = 1;
    repeated RelatedSitemapInfo related_sitemaps            = 2;
    optional int64 last_change_time                         = 3; //seconds since epoch
    optional LemurSitemapExportTimestamps export_timestamps = 4;

    required int64 timestamp                                = 10; //timestamp of source table, seconds since epoch
}

enum SitemapType {
    SITEMAP           = 0;
    SITEMAP_INDEX     = 1;
    SITEMAP_INVALID   = 2;
}

enum SitemapTypeEx
{
    ST_UNKNOWN = 0;
    ST_TEXT = 1;
    ST_XML_SITEMAP = 2;
    ST_XML_SITEMAPINDEX = 3;
    ST_XML_RSS = 4;
    ST_MALFORMED_SITEMAP = 5;
}

message SitemapError {
    optional uint32 line              = 1;
    optional SitemapErrorCode code    = 2;
    optional string text              = 3;
}

// from arcadia/robot/library/sitemap/common/error_codes.h
enum SitemapErrorCode {
    WRN_UNKNOWN_TAG                 = 1;
    WRN_TAG_CANNOT_BE_EMPTY         = 2;
    WRN_TAG_CANNOT_BE_COMPLEX       = 3;
    WRN_TAG_DATA_TOO_LONG           = 4;
    WRN_TAG_EMPTY_DATA              = 5;
    WRN_PRIORITY_INVALID            = 6;
    WRN_LASTMOD_INVALID             = 7;
    WRN_TOO_MANY_WARNINGS           = 8;
    WRN_CHANGEFREQ_INVALID          = 9;

    ERR_URL_TOO_LONG                = 100; //ERR_ERRORS;
    ERR_URL_INVALID                 = 101;

    ERR_UNKNOWN_TAG                 = 102;
    ERR_TAG_CANNOT_BE_EMPTY         = 103;
    ERR_TAG_APPEARS_TWICE           = 104;
    ERR_TAG_CANNOT_BE_COMPLEX       = 105;
    ERR_TAG_DATA_TOO_LONG           = 106;
    ERR_TAG_EMPTY_DATA              = 107;
    ERR_INCOMPLETE_URL_DATA         = 108;

    ERR_HOST_NOT_CONFIRM            = 109;
    ERR_PREFIX_DONT_MATCH           = 110;
    ERR_UNEXPECTED_ENTITY           = 111;

    ERR_DUPLICATE_ALTERNATE_HREF    = 112; // duplicated alternate lang hrefs
    ERR_MISSING_ATTRIBUTE           = 113;
    ERR_DUPLICATE_ATTRIBUTE         = 114;
    ERR_INVALID_ATTRIBUTE_VALUE     = 115;
    ERR_UNKNOWN_ATTRIBUTE           = 116;
    ERR_MISSING_ELEMENT             = 117;
    ERR_INVALID_ELEMENT_VALUE       = 118;

    ERR_INVALID_TEXT_FORMAT         = 200; //ERR_FATAL;
    ERR_INVALID_XML                 = 201;
    ERR_INVALID_MAIN_TAG            = 202;
    ERR_TOO_MANY_URLS               = 203;
    ERR_ILLEGAL_BOM                 = 204;
    ERR_INVALID_MIME_TYPE           = 250;

    ERR_HTTP_DNS_FAILURE            = 1006; //HTTP_DNS_FAILURE;
    ERR_HTTP_FILTER_DISALLOW        = 1011; //HTTP_FILTER_DISALLOW;
    ERR_HTTP_CONNECT_FAILED         = 1010; //HTTP_CONNECT_FAILED;
    ERR_HTTP_SSL_ERROR              = 1037; //HTTP_SSL_ERROR;

    WRN_MEDIA_ALLOW_EMBED_INVALID   = 300; //WRN_MEDIA;
    WRN_MEDIA_DURATION_INVALID      = 301;
    WRN_MEDIA_EXPIRATION_INVALID    = 302;
    WRN_MEDIA_VIEWS_INVALID         = 303;
    WRN_MEDIA_UPLOAD_DATE_INVALID   = 304;
    WRN_MEDIA_ADULT_FLAG_INVALID    = 305;
}

message HostRelatedSitemapMessage {
    optional ApplicationInfo application_info     = 1;
    optional MessageInfo message_info             = 2;

    optional string hostname                      = 3;
    repeated RelatedSitemapInfo related_sitemaps  = 10;
}

enum SitemapSourceId {
    ROBOTS_SOURCE_ID = 0;
    WMCLOG_SOURCE_ID = 1;
    SITEMAPINDEX_SOURCE_ID = 2;
    UNKNOWN_SOURCE_ID = 3; // unexpected Lemur source id: any source id greater or equal to this value is ignored
    WMC_ROBOTS_SOURCE_ID = 4;
}

message RelatedSitemapInfo {
    optional string url                   = 1;
    optional SitemapSourceId source_id    = 2;
    optional uint32 add_time              = 3; //seconds since epoch //FIX add_time -> http_mod_time
}

message UserSitemapMessage {
    required ApplicationInfo application_info = 1;
    required MessageInfo message_info         = 2;

    repeated UserSitemapInfo sitemaps         = 10;
}

message UserSitemapInfo {
    required uint32 add_time      = 1; //seconds since epoch
    required string sitemap_host  = 2;
    required string sitemap_url   = 3;
}

message LastSitemapChangeMessage {
    required ApplicationInfo application_info = 1;
    required MessageInfo message_info         = 2;

    required int64 timestamp  = 3; //seconds since epoch
    required string url       = 4;
}
