import { DATA_URL, PROCEDURES } from 'config'
import { callApi } from 'helpers'

const proc = PROCEDURES

export type AgreementsType = {
  agreement_id: number,
  email: string,
  ip_adress: null,
  is_agreement_privacy_policy: boolean,
  is_agreement_terms_conditions: boolean,
  status: number,
  ts_agreement: null,
  user_id: number,
}

export type SetAgreementsType = {
  _p_status: 1,
}

export type SetAgreementsTypeError = {
  _p_status: 2,
  error: string,
}

export const getAgreements = async (_p_email: string): Promise<AgreementsType> => {
  const config = {
    body: {
      params: {
        _p_email,
      },
      proc: proc.get_user_agreemens,
    },
  }

  return callApi({
    config,
    url: DATA_URL,
  })
}

export const setAgreements = async (_p_email: string): Promise<SetAgreementsType
| SetAgreementsTypeError> => {
  const config = {
    body: {
      params: {
        _p_email,
        _p_is_agreement_privacy_policy: true,
        _p_is_agreement_terms_conditions: true,
      },
      proc: proc.set_user_agreements,
    },
  }

  return callApi({
    config,
    url: DATA_URL,
  })
}
