import * as React from 'react';
import gql from 'graphql-tag';
import { inject } from 'mobx-react';

import { IMeQueryProps, MeQuery } from './types';

export const RATEPLANS = gql`
  query myRateplans($accountInput: AccountInput) {
    me(input: $accountInput) {
      ssn
      rateplans {
        id
        shortTitle
        title
      }
    }
  }
`;

export const ALLRATEPLANS = gql`
  query rateplans {
    rateplans {
      id
      title
      isPrepaid
      availableServicepacks {
        servicepackType
        servicepacks {
          id
          title
          price
          forSale
        }
      }
    }
  }
`;

@inject('authentication')
export default class Query extends React.Component<IMeQueryProps> {
  render() {
    const {
      authentication: { accountInput },
      variables,
      children,
      ...rest
    } = this.props;

    return (
      <MeQuery query={RATEPLANS} variables={{ accountInput, ...variables }} {...rest}>
        {(result) => children(result)}
      </MeQuery>
    );
  }
}
