# frozen_string_literal: true

module Billfixers
  module Partner
    PROVIDER_FRAGMENT = %(
      id
      name
      services
      billFields
      logo {
        thumbnailUrl
        smallUrl
        mediumUrl
      }
    )

    CUSTOMER_FRAGMENT = %(
      id
      email
      name
      firstName
      lastName
      phoneNumber
      avatarUrl
      b2b
      createdAt
      updatedAt
    )

    BILL_ITEM_FRAGMENT = %(
      name
      prePrice
      postPrice
      duration
      savings
      savingsStartOn
      savingsEndOn
      underContract
      createdAt
      updatedAt
    )

    BILL_FRAGMENT = %(
      id
      status
      title
      providerId
      totalSavings
      createdAt
      updatedAt

      items {
        #{BILL_ITEM_FRAGMENT}
      }
      customer {
        #{CUSTOMER_FRAGMENT}
      }
      provider {
        #{PROVIDER_FRAGMENT}
      }
    )

    OFFER_FRAGMENT = %(
      id
      status
      content
      contentHtml
      daysUntilExpiration
      createdAt
      updatedAt
      acceptedAt
      rejectedAt

      customer {
        #{CUSTOMER_FRAGMENT}
      }

      bill {
        #{BILL_FRAGMENT}
      }
    )

    INFORMATION_REQUEST_FRAGMENT = %(
      id
      content
      contentHtml
      createdAt
      respondedAt
      fields {
        id
        label
        placeholder
        dataType
        value
      }
    )

    LIST_PROVIDERS_QUERY = %(
      query {
        ListProviders {
          #{PROVIDER_FRAGMENT}
        }
      }
    )

    LIST_CUSTOMERS_QUERY = %(
      query($limit: Int, $offset: Int) {
        ListCustomers(
          limit: $limit,
          offset: $offset
        ) {
          totalCount
          nodes {
            #{CUSTOMER_FRAGMENT}
          }
        }
      }
    )

    LIST_BILLS_QUERY = %(
      query($limit: Int, $offset: Int, $customer_id: ID) {
        ListBills(
          limit: $limit,
          offset: $offset,
          customerId: $customer_id
        ) {
          totalCount
          nodes {
            #{BILL_FRAGMENT}
          }
        }
      }
    )

    LIST_OFFERS_QUERY = %(
      query($limit: Int, $offset: Int, $customer_id: ID, $bill_id: ID, $status: String) {
        ListOffers(
          limit: $limit,
          offset: $offset,
          customerId: $customer_id,
          billId: $bill_id,
          status: $status
        ) {
          totalCount
          nodes {
            #{OFFER_FRAGMENT}
          }
        }
      }
    )

    LIST_INFORMATION_REQUESTS_QUERY = %(
      query($limit: Int, $offset: Int, $customer_id: ID) {
        ListInformationRequests(
          limit: $limit,
          offset: $offset,
          customerId: $customer_id
        ) {
          totalCount
          nodes {
            #{INFORMATION_REQUEST_FRAGMENT}
          }
        }
      }
    )

    FIND_CUSTOMER_QUERY = %(
      query($id: ID!) {
        FindCustomer(id: $id) {
          #{CUSTOMER_FRAGMENT}
        }
      }
    )

    FIND_BILL_QUERY = %(
      query($id: ID!) {
        FindBill(id: $id) {
          #{BILL_FRAGMENT}
        }
      }
    )

    FIND_OFFER_QUERY = %(
      query($id: ID!) {
        FindOffer(id: $id) {
          #{OFFER_FRAGMENT}
        }
      }
    )

    FIND_INFORMATION_REQUEST_QUERY = %(
      query($id: ID!) {
        FindInformationRequest(id: $id) {
          #{INFORMATION_REQUEST_FRAGMENT}
        }
      }
    )

    CREATE_CUSTOMER_MUTATION = %(
      mutation($customer: CustomerAttributes!) {
        CreateCustomer(input: { customer: $customer }) {
          success
          errors
          customer {
            #{CUSTOMER_FRAGMENT}
          }
        }
      }
    )

    CREATE_BILL_MUTATION = %(
      mutation($customer_id: ID!, $bill: BillAttributes!) {
        CreateBill(input: { customerId: $customer_id, bill: $bill }) {
          success
          errors
          bill {
            #{BILL_FRAGMENT}
          }
        }
      }
    )

    STOP_NEGOTIATING_MUTATION = %(
      mutation($id: ID!) {
        StopNegotiating(input: { id: $id }) {
          success
          errors
          bill {
            #{BILL_FRAGMENT}
          }
        }
      }
    )

    RENEGOTIATE_BILL_MUTATION = %(
      mutation($id: ID!) {
        RenegotiateBill(input: { id: $id }) {
          success
          errors
          bill {
            #{BILL_FRAGMENT}
          }
        }
      }
    )

    ACCEPT_OFFER_MUTATION = %(
      mutation($id: ID!) {
        AcceptOffer(input: { id: $id }) {
          success
          errors
          offer {
            #{OFFER_FRAGMENT}
          }
        }
      }
    )

    REJECT_OFFER_MUTATION = %(
      mutation($id: ID!) {
        RejectOffer(input: { id: $id }) {
          success
          errors
          offer {
            #{OFFER_FRAGMENT}
          }
        }
      }
    )

    RESPOND_TO_INFORMATION_REQUEST = %(
      mutation($id: ID!, $ir: InformationRequestAttributes!) {
        RespondToInformationRequest(input: {
          id: $id,
          informationRequest: $ir
        }) {
          success
          errors
          informationRequest {
            #{INFORMATION_REQUEST_FRAGMENT}
          }
        }
      }
    )

    CALCULATE_SAVINGS_ESTIMATE = %(
      query(
        $providerId: ID!
        $currentMonthlyAmount: Float!
      ) {
        CalculateSavingsEstimate {
          estimatedAnnualSavings(
            providerId: $providerId
            currentMonthlyAmount: $currentMonthlyAmount
          )
          estimatedMonthlySavings(
            providerId: $providerId
            currentMonthlyAmount: $currentMonthlyAmount
          )
          percentageSavings(
            providerId: $providerId
            currentMonthlyAmount: $currentMonthlyAmount
          )
        }
      }
    )
  end
end