const ADD_DEMAND_TAG_TITLE = 'Demand Tags';

const ADD_DEMAND_TAG_TABLE_HEADERS = [
  {
    id: 'ID',
    label: 'UID',
    isSortable: false,
  },
  {
    id: 'NAME',
    label: 'Name',
    isSortable: false,
  },
  {
    id: 'MODEL',
    label: 'Business Model',
    isSortable: false,
  },
  {
    id: 'PRICING',
    label: 'Rate',
    isSortable: false,
  },
  {
    id: 'adRequests',
    label: 'Ad Requests',
    isSortable: false,
    align: 'right',
    withGap: true,
  },
  {
    id: 'adImpressions',
    label: 'Ad Impressions',
    isSortable: false,
    align: 'right',
    withGap: true,
  },
  {
    id: 'targeting',
    label: 'Targeting',
  },
  {
    id: 'STATUS',
    label: 'Status',
    isSortable: true,
  },
];

const ADD_DEMAND_TAG_TABLE_CELLS = [
  {
    key: 'id',
  },
  {
    key: 'name',
  },
  {
    key: 'model',
  },
  {
    key: 'pricing',
    prefix: '$',
    emptyMask: 'N/A',
  },
  {
    key: 'fields.REQUESTS',
    align: 'right',
    withPercent: true,
  },
  {
    key: 'fields.IMPRESSIONS',
    align: 'right',
    withPercent: true,
  },
  {
    key: ['include', 'exclude', 'frequency'],
  },
  {
    key: 'status',
  },
];

const ADD_SUPPLY_TAG_TITLE = 'Supply Tags';

const ADD_SUPPLY_TAG_TABLE_HEADERS = [
  {
    id: 'ID',
    label: 'UID',
    isSortable: false,
  },
  {
    id: 'NAME',
    label: 'Name',
    isSortable: false,
  },
  {
    id: 'SUPPLY_REQUESTS',
    label: 'Ad Requests',
    isSortable: false,
    align: 'right',
    withGap: true,
  },
  {
    id: 'IMPRESSIONS',
    label: 'Ad Impressions',
    isSortable: false,
    align: 'right',
    withGap: true,
  },
  {
    id: 'STATUS',
    label: 'Status',
    isSortable: false,
  },
];

const ADD_SUPPLY_TAG_TABLE_CELLS = [
  {
    key: 'id',
  },
  {
    key: 'name',
  },
  {
    key: 'fields.SUPPLY_REQUESTS',
    align: 'right',
    withPercent: true,
  },
  {
    key: 'fields.IMPRESSIONS',
    align: 'right',
    withPercent: true,
  },
  {
    key: 'status',
  },
];

export const ADD_DEMAND_TAG_DATA_QUERY = `
  query DemandTagDataQuery(
    $fields: [String],
    $sort: MarketplaceSortInputType,
    $from: Int,
    $size: Int,
    $filters: MarketplaceFiltersInputType
  ) {
    demandTagData(
      fields: $fields,
      sort: $sort,
      from: $from,
      size: $size,
      filters: $filters
    ) {
      totalCount
      data {
        id
        name
        status
        model
        aps
        pricing {
          value
        }
        frequency {
          status
          value
          amount
          type
          timeframe
        }
        include {
          domains
          geo
          os
          browsers
          playerSizes
          viewability
          devices
        }
        exclude {
          domains
          geo
          os
          browsers
        }
        fields {
          REQUESTS {
            value
            change
          }
          IMPRESSIONS {
            value
            change
          }
        }
      }
    }
  }
`;

export const ADD_SUPPLY_TAG_DATA_QUERY = `
  query SupplyTagDataQuery(
    $fields: [String],
    $sort: MarketplaceSortInputType,
    $from: Int,
    $size: Int,
    $filters: MarketplaceFiltersInputType
  ) {
    supplyTagData(
      fields: $fields,
      sort: $sort,
      from: $from,
      size: $size,
      filters: $filters
    ) {
      totalCount
      data {
        id
        name
        status
        fields {
          SUPPLY_REQUESTS {
            value
            change
          }
          IMPRESSIONS {
            value
            change
          }
        }
      }
    }
  }
`;

export const ADD_DEMAND_TAG_ACCOUNTS_QUERY = `
  query DemandAccountsDataQuery(
    $fields: [String],
    $sort: MarketplaceSortInputType,
    $from: Int,
    $size: Int,
    $filters: MarketplaceFiltersInputType
  ) {
    demandAccountsData(
      fields: $fields,
      sort: $sort,
      from: $from,
      size: $size,
      filters: $filters
    ) {
      totalCount
      data {
        id
        name
      }
    }
  }
`;

export const ADD_SUPPLY_TAG_ACCOUNTS_QUERY = `
  query SupplyAccountsDataQuery(
    $fields: [String],
    $sort: MarketplaceSortInputType,
    $from: Int,
    $size: Int,
    $filters: MarketplaceFiltersInputType
  ) {
    supplyAccountsData(
      fields: $fields,
      sort: $sort,
      from: $from,
      size: $size,
      filters: $filters
    ) {
      totalCount
      data {
        id
        name
      }
    }
  }
`;

export const ADD_DEMAND_TAG_CONFIG = {
  title: ADD_DEMAND_TAG_TITLE,
  headers: ADD_DEMAND_TAG_TABLE_HEADERS,
  cells: ADD_DEMAND_TAG_TABLE_CELLS,
  query: ADD_DEMAND_TAG_DATA_QUERY,
  accountsQuery: ADD_DEMAND_TAG_ACCOUNTS_QUERY,
  fields: ['REQUESTS', 'IMPRESSIONS', 'HB_RATE'],
  selfServeConfig: {
    headers: ADD_DEMAND_TAG_TABLE_HEADERS.filter((item) => !['ID', 'MODEL'].includes(item.id)),
    cells: ADD_DEMAND_TAG_TABLE_CELLS.filter((item) => !['id', 'model'].includes(item.key)),
  },
};

export const ADD_SUPPLY_TAG_CONFIG = {
  title: ADD_SUPPLY_TAG_TITLE,
  headers: ADD_SUPPLY_TAG_TABLE_HEADERS,
  cells: ADD_SUPPLY_TAG_TABLE_CELLS,
  query: ADD_SUPPLY_TAG_DATA_QUERY,
  accountsQuery: ADD_SUPPLY_TAG_ACCOUNTS_QUERY,
  fields: ['SUPPLY_REQUESTS', 'IMPRESSIONS'],
  selfServeConfig: {
    headers: ADD_SUPPLY_TAG_TABLE_HEADERS,
    cells: ADD_SUPPLY_TAG_TABLE_CELLS,
  },
};
