import { SORT_ASC } from '@/modules/@common/constants/sort';

import {
  CHART_COMMON_DEFAULT_CONFIG,
  COMMON_COMPARISON_PARAMS,
  COMMON_SUPPLY_COMPARISON_OPTIONS,
  COMMON_SUPPLY_TIME_INTERVAL_PARAMS,
  COMMON_TIME_INTERVAL_OPTIONS,
  LOG_PARAMS,
} from './chart';
import { STATUS_FILTERS } from './table';

export const SUPPLY_TAG_PAGE = 'SUPPLY_TAG_PAGE';

export const SUPPLY_TAG_PAGE_PATHNAME = '/tags';

export const SUPPLY_TAG_PAGE_PRICE_MODEL = [
  {
    label: 'Page Load CPM',
    value: 'CPM',
  },
  {
    label: 'Impressions CPM',
    value: 'IMPRESSIONS_CPM',
  },
  {
    label: 'Rev-Share',
    value: 'REV_SHARE',
  },
];

export const TIERS = [
  {
    label: '0',
    value: 0,
  },
  {
    label: '1',
    value: 1,
  },
  {
    label: '2',
    value: 2,
  },
  {
    label: '3',
    value: 3,
  },
  {
    label: '4',
    value: 4,
  },
  {
    label: '5',
    value: 5,
  },
  {
    label: '6',
    value: 6,
  },
  {
    label: '7',
    value: 7,
  },
  {
    label: '8',
    value: 8,
  },
  {
    label: '9',
    value: 9,
  },
];

export const SUPPLY_TAG_PAGE_ADD_DEMAND_TAG_MODAL = 'SUPPLY_TAG_PAGE_ADD_DEMAND_TAG_MODAL';
export const SUPPLY_TAG_PAGE_CHANGE_TIER_MODAL = 'SUPPLY_TAG_PAGE_CHANGE_TIER_MODAL';

export const SUPPLY_TAG_PAGE_TABLE_HEADERS = [
  // only for admin
  {
    id: 'TIER_PRIORITY',
    label: 'Tier',
    isSortable: true,
  },
  // only for admin
  {
    id: 'priority',
    label: 'Priority',
    isSortable: false,
  },
  {
    id: 'NAME',
    label: 'Name',
    isSortable: true,
    defaultSortOrder: SORT_ASC,
  },
  {
    id: 'PRICING',
    label: 'Rate',
  },
  // only for admin
  {
    id: 'AD_SERVING_FEES',
    isSortable: true,
    label: 'S.Fee',
  },
  // only for admin
  {
    id: 'REQUESTS',
    label: 'Requests',
    isSortable: true,
    align: 'right',
    withGap: true,
  },
  {
    id: 'OPPORTUNITIES',
    label: 'Opportunities',
    isSortable: true,
    align: 'right',
    withGap: true,
  },
  {
    id: 'IMPRESSIONS',
    label: 'Impressions',
    isSortable: true,
    align: 'right',
    withGap: true,
  },
  // only for self serve
  {
    id: 'PUB_REVENUE',
    label: 'Pub Revenue',
    isSortable: true,
    align: 'right',
    withGap: true,
  },
  // only for admin
  {
    id: 'GROSS_REVENUE',
    label: 'Gross Revenue',
    isSortable: true,
    align: 'right',
    withGap: true,
  },
  // only for admin
  {
    id: 'PROFIT',
    label: 'Profit',
    isSortable: true,
    align: 'right',
    withGap: true,
  },
  // only for admin
  {
    id: 'REVENUE',
    label: 'Revenue',
    isSortable: true,
    align: 'right',
    withGap: true,
  },
  {
    id: 'PUB_NET_REVENUE',
    label: 'Pub NET Revenue',
    isSortable: true,
    align: 'right',
    withGap: true,
  },
  {
    id: 'ERPM',
    label: 'eRPM',
    isSortable: true,
  },
  {
    id: 'PUB_ERPM',
    label: 'eRPM',
    isSortable: true,
  },
  // only for admin
  {
    id: 'EPPM',
    label: 'ePPM',
    isSortable: true,
  },
  // only for admin
  {
    id: 'NET_ERPM',
    label: 'Pub NET eRPM',
    isSortable: true,
  },
  {
    id: 'REQUESTS_FILL',
    label: 'Req Fill',
    isSortable: true,
    align: 'right',
    withGap: true,
  },
  {
    id: 'OPPORTUNITIES_FILL',
    label: 'Opp Fill',
    isSortable: true,
    align: 'right',
    withGap: true,
  },
  {
    id: 'REQ_ERPM',
    label: 'Req eRPM',
    isSortable: true,
  },
  {
    id: 'PUB_REQ_ERPM',
    label: 'Req eRPM',
    isSortable: true,
  },
  // only for admin
  {
    id: 'REQ_EPPM',
    label: 'Req ePPM',
    isSortable: true,
  },
  // only for admin
  {
    id: 'REQ_NET_ERPM',
    label: 'Req Pub NET eRPM',
    isSortable: true,
  },
  {
    id: 'CTR',
    label: 'CTR',
    align: 'right',
    withGap: true,
    isSortable: true,
  },
  {
    id: 'COMPLETION_RATE',
    label: 'Completion Rate',
    align: 'right',
    withGap: true,
    isSortable: true,
  },
  {
    id: 'targeting',
    label: 'Targeting',
    isSortable: false,
  },
  // only for admin
  {
    id: 'STATUS',
    label: 'Status',
    isSortable: false,
  },
];

export const SUPPLY_TAG_PAGE_TABLE_HEADERS_FOR_DISPLAY_FORMAT = [
  // only for admin
  {
    id: 'TIER_PRIORITY',
    label: 'Tier',
    isSortable: true,
  },
  // only for admin
  {
    id: 'priority',
    label: 'Priority',
    isSortable: false,
  },
  {
    id: 'NAME',
    label: 'Name',
    isSortable: true,
    defaultSortOrder: SORT_ASC,
  },
  {
    id: 'PRICING',
    label: 'Rate',
  },
  // only for admin
  {
    id: 'AD_SERVING_FEES',
    isSortable: true,
    label: 'S.Fee',
  },
  // only for admin
  {
    id: 'REQUESTS',
    label: 'Requests',
    isSortable: true,
    align: 'right',
    withGap: true,
  },
  {
    id: 'IMPRESSIONS',
    label: 'Impressions',
    isSortable: true,
    align: 'right',
    withGap: true,
  },
  // only for self serve
  {
    id: 'PUB_REVENUE',
    label: 'Pub Revenue',
    isSortable: true,
    align: 'right',
    withGap: true,
  },
  // only for admin
  {
    id: 'GROSS_REVENUE',
    label: 'Gross Revenue',
    isSortable: true,
    align: 'right',
    withGap: true,
  },
  // only for admin
  {
    id: 'PROFIT',
    label: 'Profit',
    isSortable: true,
    align: 'right',
    withGap: true,
  },
  // only for admin
  {
    id: 'REVENUE',
    label: 'Revenue',
    isSortable: true,
    align: 'right',
    withGap: true,
  },
  {
    id: 'PUB_NET_REVENUE',
    label: 'Pub NET Revenue',
    isSortable: true,
    align: 'right',
    withGap: true,
  },
  // only for admin
  {
    id: 'ACTUAL_RPM',
    label: 'Actual RPM',
    isSortable: true,
    align: 'right',
    withGap: true,
  },
  {
    id: 'REQUESTS_FILL',
    label: 'Req Fill',
    isSortable: true,
    align: 'right',
    withGap: true,
  },
  {
    id: 'REQ_ERPM',
    label: 'Req eRPM',
    isSortable: true,
  },
  // only for admin
  {
    id: 'REQ_EPPM',
    label: 'Req ePPM',
    isSortable: true,
  },
  // only for admin
  {
    id: 'REQ_NET_ERPM',
    label: 'Req Pub NET eRPM',
    isSortable: true,
  },
  {
    id: 'targeting',
    label: 'Targeting',
    isSortable: false,
  },
  // only for admin
  {
    id: 'STATUS',
    label: 'Status',
    isSortable: false,
  },
];

export const SUPPLY_TAG_PAGE_TABLE_CELLS = [
  {
    key: 'tier',
  },
  {
    key: 'priority',
  },
  {
    key: ['name', 'dtPriority'],
  },
  {
    key: 'pricing',
    prefix: '$',
    emptyMask: 'N/A',
  },
  {
    key: 'adServingFee',
    prefix: '$',
    emptyMask: 'N/A',
  },
  {
    key: 'fields.REQUESTS',
    align: 'right',
    withPercent: true,
  },
  {
    key: 'fields.OPPORTUNITIES',
    align: 'right',
    withPercent: true,
  },
  {
    key: 'fields.IMPRESSIONS',
    align: 'right',
    withPercent: true,
  },
  {
    key: 'fields.PUB_REVENUE',
    align: 'right',
    prefix: '$',
    withPercent: true,
  },
  {
    key: 'fields.GROSS_REVENUE',
    align: 'right',
    prefix: '$',
    withPercent: true,
  },
  {
    key: 'fields.PROFIT',
    align: 'right',
    prefix: '$',
    withPercent: true,
  },
  {
    key: 'fields.REVENUE',
    align: 'right',
    prefix: '$',
    withPercent: true,
  },
  {
    key: 'fields.PUB_NET_REVENUE',
    align: 'right',
    prefix: '$',
    withPercent: true,
  },
  {
    key: 'fields.ERPM',
    prefix: '$',
  },
  {
    key: 'fields.PUB_ERPM',
    prefix: '$',
  },
  {
    key: 'fields.EPPM',
    prefix: '$',
  },
  {
    key: 'fields.NET_ERPM',
    prefix: '$',
  },
  {
    key: 'fields.REQUESTS_FILL',
    align: 'right',
    postfix: '%',
    needMultiply: true,
    withPercent: true,
  },
  {
    key: 'fields.OPPORTUNITIES_FILL',
    align: 'right',
    postfix: '%',
    needMultiply: true,
    withPercent: true,
  },
  {
    key: 'fields.REQ_ERPM',
    prefix: '$',
  },
  {
    key: 'fields.PUB_REQ_ERPM',
    prefix: '$',
  },
  {
    key: 'fields.REQ_EPPM',
    prefix: '$',
  },
  {
    key: 'fields.REQ_NET_ERPM',
    prefix: '$',
  },
  {
    key: 'fields.CTR',
    align: 'right',
    postfix: '%',
    needMultiply: true,
    withPercent: true,
  },
  {
    key: 'fields.COMPLETION_RATE',
    align: 'right',
    postfix: '%',
    needMultiply: true,
    withPercent: true,
  },
  {
    key: [
      'include',
      'exclude',
      'frequency',
      'advertiserInclude',
      'advertiserExclude',
      'waterfallSkip',
      'viewabilityThreshold',
      'kvTargeting',
    ],
  },
  {
    key: 'status',
  },
];

export const SUPPLY_TAG_PAGE_TABLE_CELLS_FOR_DISPLAY_FORMAT = [
  {
    key: 'tier',
  },
  {
    key: 'priority',
  },
  {
    key: ['name', 'dtPriority'],
  },
  {
    key: 'pricing',
    prefix: '$',
    emptyMask: 'N/A',
  },
  {
    key: 'adServingFee',
    prefix: '$',
    emptyMask: 'N/A',
  },
  {
    key: 'fields.REQUESTS',
    align: 'right',
    withPercent: true,
  },
  {
    key: 'fields.IMPRESSIONS',
    align: 'right',
    withPercent: true,
  },
  {
    key: 'fields.PUB_REVENUE',
    align: 'right',
    prefix: '$',
    withPercent: true,
  },
  {
    key: 'fields.GROSS_REVENUE',
    align: 'right',
    prefix: '$',
    withPercent: true,
  },
  {
    key: 'fields.PROFIT',
    align: 'right',
    prefix: '$',
    withPercent: true,
  },
  {
    key: 'fields.REVENUE',
    align: 'right',
    prefix: '$',
    withPercent: true,
  },
  {
    key: 'fields.PUB_NET_REVENUE',
    align: 'right',
    prefix: '$',
    withPercent: true,
  },
  {
    key: 'fields.ACTUAL_RPM',
    align: 'right',
    prefix: '$',
    withPercent: true,
  },
  {
    key: 'fields.REQUESTS_FILL',
    align: 'right',
    postfix: '%',
    needMultiply: true,
    withPercent: true,
  },
  {
    key: 'fields.REQ_ERPM',
    prefix: '$',
  },
  {
    key: 'fields.REQ_EPPM',
    prefix: '$',
  },
  {
    key: 'fields.REQ_NET_ERPM',
    prefix: '$',
  },
  {
    key: [
      'include',
      'exclude',
      'frequency',
      'advertiserInclude',
      'advertiserExclude',
      'waterfallSkip',
      'viewabilityThreshold',
      'kvTargeting',
    ],
  },
  {
    key: 'status',
  },
];

export const SUPPLY_TAG_PAGE_INFO_ROWS = [
  {
    label: 'Ad Requests',
    value: 'SUPPLY_REQUESTS',
  },
  {
    label: 'Ad Impressions',
    value: 'IMPRESSIONS',
  },
  {
    label: 'Request Fill',
    value: 'SUPPLY_REQUESTS_FILL',
    postfix: '%',
    needMultiply: true,
  },
  // only for self serve
  {
    label: 'Pub Revenue',
    value: 'PUB_REVENUE',
    prefix: '$',
  },
  // only for admin
  {
    label: 'Revenue',
    value: 'REVENUE',
    prefix: '$',
  },
  // only for admin
  {
    label: 'Gross Revenue',
    value: 'GROSS_REVENUE',
    prefix: '$',
  },
  {
    label: 'Pub NET Revenue',
    value: 'PUB_NET_REVENUE',
    prefix: '$',
  },
  // only for admin
  {
    label: 'Expenses',
    value: 'EXPENSES',
    prefix: '$',
  },
  // only for admin
  {
    label: 'Media Cost',
    value: 'MEDIA_COST',
    prefix: '$',
  },
  // only for admin
  {
    label: 'Media Margin',
    value: 'MEDIA_MARGIN',
    prefix: '$',
  },
  {
    label: 'AC Ad RPM',
    value: 'AC_AD_RPM',
    prefix: '$',
  },
  // only for admin
  {
    label: 'Gross Ad RPM',
    value: 'GROSS_RPM',
    prefix: '$',
  },
  {
    label: 'Ad RPM',
    value: 'PUB_AD_RPM',
    prefix: '$',
  },
  {
    label: 'CTR',
    value: 'CTR',
    postfix: '%',
    needMultiply: true,
  },
  {
    label: 'Completion Rate',
    value: 'COMPLETION_RATE',
    postfix: '%',
    needMultiply: true,
  },
  {
    label: 'Request Viewability',
    value: 'SUPPLY_REQUESTS_VIEWABILITY',
    postfix: '%',
    needMultiply: true,
  },
  {
    label: 'Impression Viewability',
    value: 'IMPRESSIONS_VIEWABILITY',
    postfix: '%',
    needMultiply: true,
  },
];

export const SUPPLY_TAG_PAGE_INFO_ROWS_FOR_DISPLAY_FORMAT = [
  {
    label: 'Ad Requests',
    value: 'SUPPLY_REQUESTS',
  },
  {
    label: 'Ad Impressions',
    value: 'IMPRESSIONS',
  },
  {
    label: 'Request Fill',
    value: 'SUPPLY_REQUESTS_FILL',
    postfix: '%',
    needMultiply: true,
  },
  // only for self serve
  {
    label: 'Pub Revenue',
    value: 'PUB_REVENUE',
    prefix: '$',
  },
  // only for admin
  {
    label: 'Revenue',
    value: 'REVENUE',
    prefix: '$',
  },
  // only for admin
  {
    label: 'Gross Revenue',
    value: 'GROSS_REVENUE',
    prefix: '$',
  },
  {
    label: 'Pub NET Revenue',
    value: 'PUB_NET_REVENUE',
    prefix: '$',
  },
  // only for admin
  {
    label: 'Expenses',
    value: 'EXPENSES',
    prefix: '$',
  },
  // only for admin
  {
    label: 'Media Cost',
    value: 'MEDIA_COST',
    prefix: '$',
  },
  // only for admin
  {
    label: 'Media Margin',
    value: 'MEDIA_MARGIN',
    prefix: '$',
  },
  {
    label: 'AC Ad RPM',
    value: 'AC_AD_RPM',
    prefix: '$',
  },
  // only for admin
  {
    label: 'Gross Ad RPM',
    value: 'GROSS_RPM',
    prefix: '$',
  },
  {
    label: 'Ad RPM',
    value: 'PUB_AD_RPM',
    prefix: '$',
  },
  {
    label: 'Request Viewability',
    value: 'SUPPLY_REQUESTS_VIEWABILITY',
    postfix: '%',
    needMultiply: true,
  },
  {
    label: 'Impression Viewability',
    value: 'IMPRESSIONS_VIEWABILITY',
    postfix: '%',
    needMultiply: true,
  },
];

export const SUPPLY_TAG_PAGE_TOTAL_FIELDS = [
  'SUPPLY_REQUESTS',
  'IMPRESSIONS',
  'SUPPLY_REQUESTS_FILL',
  'REVENUE',
  'GROSS_REVENUE',
  'PUB_REVENUE',
  'MEDIA_COST',
  'AC_AD_RPM',
  'GROSS_RPM',
  'PUB_AD_RPM',
  'SUPPLY_REQUESTS_VIEWABILITY',
  'IMPRESSIONS_VIEWABILITY',
  'MEDIA_MARGIN',
  'CTR',
  'COMPLETION_RATE',
  'EXPENSES',
  'PUB_NET_REVENUE',
];

export const SUPPLY_TAG_PAGE_TOTAL_GRAPHQL_QUERY = `
  query SupplyTagDataByIdQuery(
    $fields: [String],
    $filters: MarketplaceFiltersInputType,
    $id: String!
  ) {
    supplyTagDataById(
      fields: $fields,
      filters: $filters,
      id: $id
    ) {
      fields {
        SUPPLY_REQUESTS {
          value
          change
        }
        IMPRESSIONS {
          value
          change
        }
        SUPPLY_REQUESTS_FILL {
          value
          change
        }
        REVENUE {
          value
          change
        }
        PUB_REVENUE {
          value
          change
        }
        GROSS_REVENUE {
          value
          change
        }
        MEDIA_COST {
          value
          change
        }
        AC_AD_RPM {
          value
          change
        }
        GROSS_RPM {
          value
          change
        }
        PUB_AD_RPM {
          value
          change
        }
        SUPPLY_REQUESTS_VIEWABILITY {
          value
          change
        }
        IMPRESSIONS_VIEWABILITY {
          value
          change
        }
        MEDIA_MARGIN {
          value
          change
        }
        COMPLETION_RATE {
          value
          change
        }
        CTR {
          value
          change
        }
        EXPENSES {
          value
          change
        }
        PUB_NET_REVENUE {
          value
          change
        }
      }
    }
  }
`;

export const SUPPLY_TAG_PAGE_DATA_FIELDS = [
  'REQUESTS',
  'OPPORTUNITIES',
  'IMPRESSIONS',
  'REVENUE',
  'PUB_REVENUE',
  'GROSS_REVENUE',
  'REQUESTS_FILL',
  'OPPORTUNITIES_FILL',
  'ERPM',
  'PUB_ERPM',
  'PUB_REQ_ERPM',
  'EPPM',
  'NET_ERPM',
  'HB_RATE',
  'ACTUAL_RPM',
  'COMPLETION_RATE',
  'CTR',
  'REQ_ERPM',
  'REQ_EPPM',
  'REQ_NET_ERPM',
  'PROFIT',
  'PUB_NET_REVENUE',
];

export const SUPPLY_TAG_PAGE_DATA_GRAPHQL_QUERY = `
  query DemandTagDataQuery(
    $fields: [String],
    $sort: MarketplaceSortInputType,
    $from: Int,
    $size: Int,
    $filters: MarketplaceFiltersInputType,
    $advertiserTargeting: Boolean
  ) {
    demandTagData(
      fields: $fields,
      sort: $sort,
      from: $from,
      size: $size,
      filters: $filters,
      advertiserTargeting: $advertiserTargeting
    ) {
      totalCount
      data {
        id
        name
        tier
        priority
        aps
        status
        daccountId
        advertiserId
        type
        waterfallSkip
        viewabilityThreshold
        profit
        pricing {
          value
        }
        adServingFee {
          value
        }
        frequency {
          status
          value
          amount
          type
          timeframe
        }
        include {
          domains
          geo
          os
          browsers
          playerSizes
          viewability
          devices
        }
        exclude {
          domains
          geo
          os
          browsers
          devices
        }
        advertiserInclude {
          geo
        }
        advertiserExclude {
          geo
        }
        kvTargeting {
          state
          type
          key
          values
          listNames
          keyName
        }
        dtPriority
        fields {
          REQUESTS {
            value
            change
          }
          OPPORTUNITIES {
            value
            change
          }
          IMPRESSIONS {
            value
            change
          }
          REVENUE {
            value
            change
          }
          PUB_REVENUE {
            value
            change
          }
          GROSS_REVENUE {
            value
            change
          }
          REQUESTS_FILL {
            value
            change
          }
          OPPORTUNITIES_FILL {
            value
            change
          }
          ERPM {
            value
            change
          }
          NET_ERPM {
            value
            change
          }
          EPPM {
            value
            change
          }
          ACTUAL_RPM {
            value
            change
          }
          COMPLETION_RATE {
            value
            change
          }
          CTR {
            value
            change
          }
          REQ_ERPM {
            value
            change
          }
          REQ_EPPM {
            value
            change
          }
          REQ_NET_ERPM {
            value
            change
          }
          PROFIT {
            value
            change
          }
          PUB_NET_REVENUE {
            value
            change
          }
        }
      }
    }
  }
`;

export const SUPPLY_TAG_PAGE_DATA_GRAPHQL_QUERY_SELF_SERVE = `
  query DemandTagDataSelfServeCompressedQuery(
    $fields: [String],
    $sort: MarketplaceSortInputType,
    $from: Int,
    $size: Int,
    $filters: MarketplaceFiltersInputType,
    $advertiserTargeting: Boolean
  ) {
    demandTagDataSelfServeCompressed(
      fields: $fields,
      sort: $sort,
      from: $from,
      size: $size,
      filters: $filters,
      advertiserTargeting: $advertiserTargeting
    ) {
      totalCount
      data {
        id
        name
        tier
        priority
        status
        daccountId
        advertiserId
        type
        aps
        waterfallSkip
        viewabilityThreshold
        profit
        compressed
        pricing {
          value
        }
        adServingFee {
          value
        }
        frequency {
          status
          value
          amount
          type
          timeframe
        }
        include {
          domains
          geo
          os
          browsers
          playerSizes
          viewability
          devices
        }
        exclude {
          domains
          geo
          os
          browsers
          devices
        }
        advertiserInclude {
          geo
        }
        advertiserExclude {
          geo
        }
        kvTargeting {
          state
          type
          key
          values
          listNames
          keyName
        }
        dtPriority
        fields {
          REQUESTS {
            value
            change
          }
          OPPORTUNITIES {
            value
            change
          }
          IMPRESSIONS {
            value
            change
          }
          REVENUE {
            value
            change
          }
          PUB_REVENUE {
            value
            change
          }
          GROSS_REVENUE {
            value
            change
          }
          REQUESTS_FILL {
            value
            change
          }
          OPPORTUNITIES_FILL {
            value
            change
          }
          ERPM {
            value
            change
          }
          PUB_ERPM {
            value
            change
          }
          NET_ERPM {
            value
            change
          }
          EPPM {
            value
            change
          }
          ACTUAL_RPM {
            value
            change
          }
          COMPLETION_RATE {
            value
            change
          }
          CTR {
            value
            change
          }
          REQ_ERPM {
            value
            change
          }
          PUB_REQ_ERPM {
            value
            change
          }
          REQ_EPPM {
            value
            change
          }
          REQ_NET_ERPM {
            value
            change
          }
          PROFIT {
            value
            change
          }
          PUB_NET_REVENUE {
            value
            change
          }
        }
      }
    }
  }
`;

export const SUPPLY_TAG_PAGE_HISTOGRAM_GRAPHQL_QUERY = `
  query SupplyTagHistogramQuery(
    $fields: [String],
    $interval: String,
    $timezone: String,
    $filters: [MarketplaceFiltersInputType]
  ) {
    supplyTagHistogram(
      fields: $fields,
      interval: $interval,
      timezone: $timezone,
      filters: $filters
    ) {
      totalCount
      data {
        name
        buckets {
          time
          fields {
            SUPPLY_REQUESTS {
              value
              change
            }
            IMPRESSIONS {
              value
              change
            }
            SUPPLY_REQUESTS_FILL {
              value
              change
            }
            REVENUE {
              value
              change
            }
            PUB_REVENUE {
              value
              change
            }
            GROSS_REVENUE {
              value
              change
            }
            REQUESTS_VIEWABILITY {
              value
              change
            }
            SUPPLY_REQUESTS_VIEWABILITY {
              value
              change
            }
            IMPRESSIONS_VIEWABILITY {
              value
              change
            }
            AC_AD_RPM {
              value
              change
            }
            GROSS_RPM {
              value
              change
            }
            PUB_AD_RPM {
              value
              change
            }
            PUB_NET_REVENUE {
              value
              change
            }
          }
        }
      }
    }
  }
`;

export const SUPPLY_TAG_PAGE_INFO_GRAPHQL_QUERY = `
  query SupplyTagByIdQuery(
    $id: String
  ) {
    supplyTagById(
      id: $id
    ) {
      id
      name
      source
      platformId
      created
      updated
      updatedBy
      accountId
      siteId
      status
      pricing {
        model
        value
        startDate
        endDate
      }
      expenses {
        value
        startDate
        endDate
        updatedBy
      }
      accountName
      accountType
      siteName
      floorPrice {
        floor
        viewableFloor
        firstRequestFloor
      }
      adServerUrl
      waterfallNote
      format
      publisherDemand
      displayType
      automaticOptimization {
        kpi
        period
        frequency
        hbTiers
        kpiGap
      }
      automaticFloorPrice {
        fillRateThreshold
        minimumFloor
        maximumFloor
      }
    }
  }
`;

export const SUPPLY_TAG_PAGE_INFO_GRAPHQL_QUERY_SELF_SERVE = `
  query SupplyTagByIdQuery(
    $id: String
  ) {
    supplyTagById(
      id: $id
    ) {
      id
      name
      source
      platformId
      created
      updated
      updatedBy
      accountId
      siteId
      status
      accountName
      accountType
      siteName
      adServerUrl
      format
      publisherDemand
      displayType
    }
  }
`;

export const SUPPLY_TAG_PAGE_TABS_VAST = [
  {
    label: 'Demand',
    dataId: 'main',
    contentKey: 'main',
  },
  {
    label: 'Settings',
    dataId: 'supplyTagSettings',
    contentKey: 'supplyTagSettings',
  },
  {
    label: 'Optimization',
    dataId: 'automaticOptimization',
    contentKey: 'automaticOptimization',
  },
  {
    label: 'Export Tag',
    dataId: 'exportSupplyTag',
    contentKey: 'exportSupplyTag',
  },
];

export const SUPPLY_TAG_PAGE_CONFIG = {
  type: SUPPLY_TAG_PAGE,
  tabs: [
    {
      label: 'Demand',
      dataId: 'main',
      contentKey: 'main',
    },
    {
      label: 'Settings',
      dataId: 'supplyTagSettings',
      contentKey: 'supplyTagSettings',
    },
    {
      label: 'Optimization',
      dataId: 'automaticOptimization',
      contentKey: 'automaticOptimization',
    },
  ],
  infoRows: SUPPLY_TAG_PAGE_INFO_ROWS.filter(
    (item) => !['PUB_PLAYER_ERPM', 'PUB_REVENUE', 'PUB_AD_RPM', 'PUB_ERPM', 'PUB_REQ_ERPM'].includes(item.value),
  ),
  tableSelecting: true,
  tableFilters: STATUS_FILTERS,
  // todo: replace with flag self-serve
  tableHeaders: SUPPLY_TAG_PAGE_TABLE_HEADERS.filter(
    (item) => !['PUB_PLAYER_ERPM', 'PUB_REVENUE', 'PUB_AD_RPM', 'PUB_ERPM', 'PUB_REQ_ERPM'].includes(item.id),
  ),
  tableCells: SUPPLY_TAG_PAGE_TABLE_CELLS.filter(
    (item) =>
      ![
        'fields.PUB_PLAYER_ERPM',
        'fields.PUB_REVENUE',
        'fields.PUB_AD_RPM',
        'fields.PUB_ERPM',
        'fields.PUB_REQ_ERPM',
      ].includes(item.key),
  ),
  timeIntervalOptions: COMMON_TIME_INTERVAL_OPTIONS,
  timeIntervalParams: COMMON_SUPPLY_TIME_INTERVAL_PARAMS,
  chartLogParams: LOG_PARAMS,
  comparisonOptions: [
    ...COMMON_SUPPLY_COMPARISON_OPTIONS,
    {
      label: 'AC Ad RPM',
      value: 'AC_AD_RPM',
    },
    {
      label: 'Gross Ad RPM',
      value: 'GROSS_RPM',
    },
    {
      label: 'Request Viewability',
      value: 'SUPPLY_REQUESTS_VIEWABILITY',
    },
    {
      label: 'Impression Viewability',
      value: 'IMPRESSIONS_VIEWABILITY',
    },
  ],
  comparisonParams: COMMON_COMPARISON_PARAMS,
  setRowBackgroundBy: true,
  rowsPerPageOptions: [10, 25, 50, 100, 200],
  defaultConfig: {
    ...CHART_COMMON_DEFAULT_CONFIG,
    rowsPerPage: 50,
    sortBy: 'TIER_PRIORITY',
    sortOrder: 'ASC',
    filterByStatus: STATUS_FILTERS[1].value,
  },
  totalFields: SUPPLY_TAG_PAGE_TOTAL_FIELDS,
  totalQuery: SUPPLY_TAG_PAGE_TOTAL_GRAPHQL_QUERY,
  dataFields: SUPPLY_TAG_PAGE_DATA_FIELDS,
  dataQuery: SUPPLY_TAG_PAGE_DATA_GRAPHQL_QUERY,
  histogramQuery: SUPPLY_TAG_PAGE_HISTOGRAM_GRAPHQL_QUERY,
  infoQuery: SUPPLY_TAG_PAGE_INFO_GRAPHQL_QUERY,
  isOpenNewTab: true,
  showHistoryCSVButton: true,
  selfServeConfig: {
    infoQuery: SUPPLY_TAG_PAGE_INFO_GRAPHQL_QUERY_SELF_SERVE,
    tabs: [
      {
        label: 'Demand',
        dataId: 'main',
        contentKey: 'main',
      },
      {
        label: 'Settings',
        dataId: 'supplyTagSettings',
        contentKey: 'supplyTagSettings',
      },
    ],
    dataQuery: SUPPLY_TAG_PAGE_DATA_GRAPHQL_QUERY_SELF_SERVE,
    infoRows: SUPPLY_TAG_PAGE_INFO_ROWS.filter(
      (item) =>
        ![
          'PLAYER_ERPM',
          'REVENUE',
          'GROSS_REVENUE',
          'EXPENSES',
          'MEDIA_COST',
          'MEDIA_MARGIN',
          'AC_AD_RPM',
          'GROSS_RPM',
          'ERPM',
          'REQ_ERPM',
        ].includes(item.value),
    ),
    comparisonOptions: [
      {
        label: 'Ad Requests',
        value: 'SUPPLY_REQUESTS',
      },
      {
        label: 'Ad Impressions',
        value: 'IMPRESSIONS',
      },
      {
        label: 'Request Fill',
        value: 'SUPPLY_REQUESTS_FILL',
      },
      {
        label: 'Pub Revenue',
        value: 'PUB_REVENUE',
      },
      {
        label: 'Pub NET Revenue',
        value: 'PUB_NET_REVENUE',
      },
      {
        label: 'Ad RPM',
        value: 'PUB_AD_RPM',
      },
      {
        label: 'Request Viewability',
        value: 'SUPPLY_REQUESTS_VIEWABILITY',
      },
      {
        label: 'Impression Viewability',
        value: 'IMPRESSIONS_VIEWABILITY',
      },
    ],
    tableHeaders: SUPPLY_TAG_PAGE_TABLE_HEADERS.filter(
      (item) =>
        ![
          'PLAYER_ERPM',
          'TIER_PRIORITY',
          'priority',
          'AD_SERVING_FEES',
          'REQUESTS',
          'GROSS_REVENUE',
          'GROSS_RPM',
          'PROFIT',
          'REVENUE',
          'EPPM',
          'NET_ERPM',
          'REQ_EPPM',
          'REQ_NET_ERPM',
          'ACTUAL_RPM',
          'STATUS',
          'ERPM',
          'REQ_ERPM',
        ].includes(item.id),
    ),
    tableCells: SUPPLY_TAG_PAGE_TABLE_CELLS.filter(
      (item) =>
        ![
          'fields.PLAYER_ERPM',
          'tier',
          'priority',
          'adServingFee',
          'fields.REQUESTS',
          'fields.GROSS_REVENUE',
          'fields.GROSS_RPM',
          'fields.PROFIT',
          'fields.REVENUE',
          'fields.EPPM',
          'fields.NET_ERPM',
          'fields.REQ_EPPM',
          'fields.REQ_NET_ERPM',
          'fields.ACTUAL_RPM',
          'fields.ERPM',
          'fields.REQ_ERPM',
          'status',
        ].includes(item.key),
    ),
    disableDuplicate: true,
    // defaultConfig for Self Serve MP
    defaultConfig: {
      comparisonFilter: 'SUPPLY_REQUESTS',
      sortBy: 'PUB_REVENUE',
      sortOrder: 'DESC',
    },
  },
};

export const AUTOMATIC_OPTIMIZATION = {
  enabled: true,
  disabled: false,
};

export const SUPPLY_TAG_PUBLISHER_DEMAND_ONLY = {
  enabled: true,
  disabled: false,
};

export const AUTOMATIC_OPTIMIZATION_KPI_VIDEO = [
  {
    label: 'Pub NET eRPM',
    value: 'NET_ERPM',
  },
  {
    label: 'ePPM',
    value: 'EPPM',
  },
  {
    label: 'Req Fill',
    value: 'REQ_FILL',
  },
  {
    label: 'Opp Fill',
    value: 'OPP_FILL',
  },
  {
    label: 'Req eRPM',
    value: 'REQ_ERPM',
  },
  {
    label: 'Req ePPM',
    value: 'REQ_EPPM',
  },
  {
    label: 'Req Pub NET eRPM',
    value: 'REQ_NET_ERPM',
  },
];

export const AUTOMATIC_OPTIMIZATION_KPI_DISPLAY = [
  {
    label: 'Actual RPM',
    value: 'ACTUAL_RPM',
  },
  {
    label: 'Req Fill',
    value: 'REQ_FILL',
  },
  {
    label: 'Req eRPM',
    value: 'REQ_ERPM',
  },
  {
    label: 'Req ePPM',
    value: 'REQ_EPPM',
  },
  {
    label: 'Req Pub NET eRPM',
    value: 'REQ_NET_ERPM',
  },
];

export const AUTOMATIC_OPTIMIZATION_PERIOD = [
  {
    label: 'Last 15 Minutes',
    value: 'MINUTE_15',
  },
  {
    label: 'Last 30 Minutes',
    value: 'MINUTE_30',
  },
  {
    label: 'Last 60 Minutes',
    value: 'MINUTE_60',
  },
  {
    label: 'Last 120 Minutes',
    value: 'MINUTE_120',
  },
  {
    label: 'Last 180 Minutes',
    value: 'MINUTE_180',
  },
  {
    label: 'Today',
    value: 'TODAY',
  },
  {
    label: 'Last 24 hours',
    value: 'HOUR_24',
  },
  {
    label: 'Last 7 days',
    value: 'DAY_7',
  },
];

export const AUTOMATIC_OPTIMIZATION_FREQUENCY = [
  {
    label: 'Every 2 hours',
    value: 'HOUR_2',
  },
  {
    label: 'Every 4 hours',
    value: 'HOUR_4',
  },
  {
    label: 'Every 8 hours',
    value: 'HOUR_8',
  },
  {
    label: 'Every 16 hours',
    value: 'HOUR_16',
  },
  {
    label: 'Every 24 hours',
    value: 'HOUR_24',
  },
];

export const AUTOMATIC_OPTIMIZATION_TIERS = [
  {
    label: '2',
    value: 'TIER_2',
  },
  {
    label: '3',
    value: 'TIER_3',
  },
  {
    label: '4',
    value: 'TIER_4',
  },
];

export const SUPPLY_TAG_PRICING_TYPE_PRICING = 'pricing';

export const SUPPLY_TAG_PRICING_TYPE_EXPENSES = 'expenses';

export const SUPPLY_TAG_PRICING_TYPE = {
  pricing: SUPPLY_TAG_PRICING_TYPE_PRICING,
  expenses: SUPPLY_TAG_PRICING_TYPE_EXPENSES,
};

export const SOURCE_TAG_OPTIONS = [
  {
    label: 'Marketplace',
    value: 'MARKETPLACE',
  },
  {
    label: 'Anyclip (TM)',
    value: 'ANYCLIP',
  },
  {
    label: 'Google External',
    value: 'GOOGLE_EXTERNAL',
  },
  {
    label: 'SpringServe',
    value: 'SPRINGSERVE',
  },
  {
    label: 'SpringServe External',
    value: 'SPRINGSERVE_EXTERNAL',
  },
  {
    label: 'XE External',
    value: 'XE_EXTERNAL',
  },
];

export const DISPLAY_TYPE_OPTIONS = [
  {
    label: 'Fallback',
    value: 'FALLBACK',
  },
  {
    label: 'Overlay',
    value: 'OVERLAY',
  },
];
