import { Response } from 'redux/Common/types'

import { DEFAULT_ANALYTICS_API_CONFIG } from './api.config'

import Api from './api'

import {
  AnalyticChartData,
  AnalyticsTalentClickRequest,
  AnalyticsTalentEarningRequest,
  AnalyticsTalentModuleRequest,
  AnalyticsTalentViewRequest
} from 'models/analytic-chart/analytic-chart.model'

import { CancelToken } from 'axios'

export default class AnalyticsApi extends Api {
  constructor() {
    super(DEFAULT_ANALYTICS_API_CONFIG)
  }

  async analyticsTalentProfileAvgCTR(
    params: AnalyticsTalentViewRequest
  ): Promise<Response<AnalyticChartData>> {
    return this.getRequest(`/v1/chart/average-ctr`, params)
  }

  async analyticsTalentProfileView(
    params: AnalyticsTalentViewRequest
  ): Promise<Response<AnalyticChartData>> {
    return this.getRequest(`/v1/chart/total-views`, params)
  }

  async analyticsTalentProfileEarning(
    params: AnalyticsTalentViewRequest
  ): Promise<Response<AnalyticChartData>> {
    return this.getRequest(`/v1/chart/total-earnings`, params)
  }

  async analyticsTalentProfileClick(
    params: AnalyticsTalentClickRequest
  ): Promise<Response<AnalyticChartData>> {
    return this.getRequest(`/v1/chart/total-clicks`, params)
  }

  async analyticsTalentModuleAnalytics(
    params: AnalyticsTalentModuleRequest,
    cancelToken?: CancelToken
  ): Promise<Response<AnalyticChartData>> {
    return this.getRequest(`/v1/chart/talent-module`, params, cancelToken)
  }
}

export interface IAnalyticsApi {
  analyticsTalentProfileAvgCTR(
    params: AnalyticsTalentViewRequest
  ): Promise<Response<AnalyticChartData>>

  analyticsTalentProfileView(
    params: AnalyticsTalentViewRequest
  ): Promise<Response<AnalyticChartData>>

  analyticsTalentProfileEarning(
    params: AnalyticsTalentEarningRequest
  ): Promise<Response<AnalyticChartData>>

  analyticsTalentProfileClick(
    params: AnalyticsTalentClickRequest
  ): Promise<Response<AnalyticChartData>>

  analyticsTalentModuleAnalytics(
    params: AnalyticsTalentModuleRequest,
    cancelToken?: CancelToken
  ): Promise<Response<AnalyticChartData>>
}
