import gql from "graphql-tag"

// used in Availability component (homepage)
const GET_STOCK_TOTALS = gql`
  query StockList($cursor: Int!) {
    listPlasmids(input: { cursor: $cursor, limit: 30000 }) {
      totalCount
    }
    listStrains(input: { cursor: $cursor, limit: 30000 }) {
      totalCount
    }
  }
`

const GET_STRAIN_LIST = gql`
  query StrainList($cursor: Int!, $filter: String!) {
    listStrains(input: { cursor: $cursor, limit: 10, filter: $filter }) {
      nextCursor
      strains {
        id
        label
        summary
        in_stock
      }
    }
  }
`

const GET_PLASMID_LIST = gql`
  query PlasmidListFilter($cursor: Int!, $filter: String!) {
    listPlasmids(input: { cursor: $cursor, limit: 10, filter: $filter }) {
      nextCursor
      plasmids {
        id
        name
        summary
        in_stock
      }
    }
  }
`

const GET_RELATED_STRAINS = gql`
  query StrainList($filter: String!) {
    listStrains(input: { limit: 10, filter: $filter }) {
      strains {
        id
        label
      }
    }
  }
`

const GET_PLASMID = gql`
  query Plasmid($id: ID!) {
    plasmid(id: $id) {
      id
      name
      summary
      depositor
      publications {
        id
        doi
      }
      dbxrefs
      genes
      image_map
      sequence
      keywords
      genbank_accession
      in_stock
    }
  }
`

const GET_STRAIN = gql`
  query Strain($id: ID!) {
    strain(id: $id) {
      id
      label
      summary
      species
      parent {
        id
        label
      }
      depositor
      plasmid
      dbxrefs
      publications {
        id
        doi
      }
      genes
      in_stock
      systematic_name
      genotypes
      mutagenesis_method
      genetic_modification
      names
      characteristics
    }
  }
`

/**
 * query will still need these from annotations:
      phenotypes {
        phenotype
        note
        assay
        environment
        publication {
         doi
         id
        }
      }
 */

const GET_REFRESH_TOKEN = gql`
  query GetRefreshToken($token: string!) {
    getRefreshToken(token: $token) {
      token
    }
  }
`

// MUTATIONS

const LOGIN = gql`
  mutation Login($input: LoginInput!) {
    login(input: $input) {
      token
      user {
        id
        email
        first_name
        last_name
        roles {
          role
          permissions {
            permission
          }
        }
      }
      identity {
        provider
      }
    }
  }
`

const LOGOUT = gql`
  mutation Logout {
    logout {
      success
    }
  }
`

const POST_ORDER = gql`
  mutation CreateOrder($input: CreateOrderInput!) {
    createOrder(input: $input) {
      id
    }
  }
`

export {
  GET_STOCK_TOTALS,
  GET_STRAIN_LIST,
  GET_PLASMID_LIST,
  GET_RELATED_STRAINS,
  GET_STRAIN,
  GET_PLASMID,
  GET_REFRESH_TOKEN,
  LOGIN,
  LOGOUT,
  POST_ORDER,
}

@@ -1985,16 +1985,504 @@
  %7D%0A */%0A%0A
+const GET_CONTENT_BY_SLUG = gql%60%0A  query contentBySlug($slug: String!) %7B%0A    contentBySlug(slug: $slug) %7B%0A      id%0A      content%0A      name%0A      slug%0A      created_by %7B%0A        email%0A        roles %7B%0A          role%0A          permissions %7B%0A            permission%0A            resource%0A          %7D%0A        %7D%0A      %7D%0A      updated_by %7B%0A        email%0A        roles %7B%0A          role%0A          permissions %7B%0A            permission%0A            resource%0A          %7D%0A        %7D%0A      %7D%0A    %7D%0A  %7D%0A%60%0A%0A
 const GE
@@ -2536,17 +2536,17 @@
 $token: 
-s
+S
 tring!) 
@@ -3170,16 +3170,378 @@
 %0A  %7D%0A%60%0A%0A
+const CREATE_CONTENT = gql%60%0A  mutation CreateContent($input: CreateContentInput!) %7B%0A    createContent(input: $input) %7B%0A      name%0A      created_by%0A      content%0A      namespace%0A    %7D%0A  %7D%0A%60%0A%0Aconst UPDATE_CONTENT = gql%60%0A  mutation UpdateContent($input: UpdateContentInput!) %7B%0A    updateContent(input: $input) %7B%0A      id%0A      updated_by%0A      content%0A    %7D%0A  %7D%0A%60%0A%0A
 export %7B
@@ -3652,16 +3652,39 @@
 LASMID,%0A
+  GET_CONTENT_BY_SLUG,%0A
   GET_RE
@@ -3715,16 +3715,16 @@
 LOGOUT,%0A
-
   POST_O
@@ -3729,10 +3729,46 @@
 _ORDER,%0A
+  CREATE_CONTENT,%0A  UPDATE_CONTENT,%0A
 %7D%0A

add queries and mutations for content api