import * as Types from '@vegaprotocol/types';

import { gql } from '@apollo/client';
import * as Apollo from '@apollo/client';
const defaultOptions = {} as const;
export type ProposalFieldsFragment = {
  __typename?: 'Proposal';
  id?: string | null;
  reference: string;
  state: Types.ProposalState;
  datetime: any;
  rejectionReason?: Types.ProposalRejectionReason | null;
  errorDetails?: string | null;
  rationale: {
    __typename?: 'ProposalRationale';
    title: string;
    description: string;
  };
  party: { __typename?: 'Party'; id: string };
  terms: {
    __typename?: 'ProposalTerms';
    closingDatetime: any;
    enactmentDatetime?: any | null;
    change:
      | {
          __typename: 'NewAsset';
          name: string;
          symbol: string;
          decimals: number;
          quantum: string;
          source:
            | { __typename?: 'BuiltinAsset'; maxFaucetAmountMint: string }
            | {
                __typename?: 'ERC20';
                contractAddress: string;
                withdrawThreshold: string;
                lifetimeLimit: string;
              };
        }
      | { __typename?: 'NewFreeform' }
      | {
          __typename?: 'NewMarket';
          instrument: {
            __typename?: 'InstrumentConfiguration';
            name: string;
            code: string;
            futureProduct?: {
              __typename?: 'FutureProduct';
              settlementAsset: { __typename?: 'Asset'; symbol: string };
            } | null;
          };
        }
      | {
          __typename?: 'UpdateAsset';
          quantum: string;
          assetId: string;
          source: {
            __typename?: 'UpdateERC20';
            lifetimeLimit: string;
            withdrawThreshold: string;
          };
        }
      | { __typename?: 'UpdateMarket'; marketId: string }
      | {
          __typename?: 'UpdateNetworkParameter';
          networkParameter: {
            __typename?: 'NetworkParameter';
            key: string;
            value: string;
          };
        };
  };
  votes: {
    __typename?: 'ProposalVotes';
    yes: {
      __typename?: 'ProposalVoteSide';
      totalTokens: string;
      totalNumber: string;
      totalEquityLikeShareWeight: string;
    };
    no: {
      __typename?: 'ProposalVoteSide';
      totalTokens: string;
      totalNumber: string;
      totalEquityLikeShareWeight: string;
    };
  };
};

export type ProposalsQueryVariables = Types.Exact<{ [key: string]: never }>;

export type ProposalsQuery = {
  __typename?: 'Query';
  proposalsConnection?: {
    __typename?: 'ProposalsConnection';
    edges?: Array<{
      __typename?: 'ProposalEdge';
      node: {
        __typename?: 'Proposal';
        id?: string | null;
        reference: string;
        state: Types.ProposalState;
        datetime: any;
        rejectionReason?: Types.ProposalRejectionReason | null;
        errorDetails?: string | null;
        rationale: {
          __typename?: 'ProposalRationale';
          title: string;
          description: string;
        };
        party: { __typename?: 'Party'; id: string };
        terms: {
          __typename?: 'ProposalTerms';
          closingDatetime: any;
          enactmentDatetime?: any | null;
          change:
            | {
                __typename: 'NewAsset';
                name: string;
                symbol: string;
                decimals: number;
                quantum: string;
                source:
                  | { __typename?: 'BuiltinAsset'; maxFaucetAmountMint: string }
                  | {
                      __typename?: 'ERC20';
                      contractAddress: string;
                      withdrawThreshold: string;
                      lifetimeLimit: string;
                    };
              }
            | { __typename?: 'NewFreeform' }
            | {
                __typename?: 'NewMarket';
                instrument: {
                  __typename?: 'InstrumentConfiguration';
                  name: string;
                  code: string;
                  futureProduct?: {
                    __typename?: 'FutureProduct';
                    settlementAsset: { __typename?: 'Asset'; symbol: string };
                  } | null;
                };
              }
            | {
                __typename?: 'UpdateAsset';
                quantum: string;
                assetId: string;
                source: {
                  __typename?: 'UpdateERC20';
                  lifetimeLimit: string;
                  withdrawThreshold: string;
                };
              }
            | { __typename?: 'UpdateMarket'; marketId: string }
            | {
                __typename?: 'UpdateNetworkParameter';
                networkParameter: {
                  __typename?: 'NetworkParameter';
                  key: string;
                  value: string;
                };
              };
        };
        votes: {
          __typename?: 'ProposalVotes';
          yes: {
            __typename?: 'ProposalVoteSide';
            totalTokens: string;
            totalNumber: string;
            totalEquityLikeShareWeight: string;
          };
          no: {
            __typename?: 'ProposalVoteSide';
            totalTokens: string;
            totalNumber: string;
            totalEquityLikeShareWeight: string;
          };
        };
      };
    } | null> | null;
  } | null;
};

export const ProposalFieldsFragmentDoc = gql`
  fragment ProposalFields on Proposal {
    id
    rationale {
      title
      description
    }
    reference
    state
    datetime
    rejectionReason
    party {
      id
    }
    errorDetails
    terms {
      closingDatetime
      enactmentDatetime
      change {
        ... on NewMarket {
          instrument {
            name
            code
            futureProduct {
              settlementAsset {
                symbol
              }
            }
          }
        }
        ... on UpdateMarket {
          marketId
        }
        ... on NewAsset {
          __typename
          name
          symbol
          decimals
          quantum
          source {
            ... on BuiltinAsset {
              maxFaucetAmountMint
            }
            ... on ERC20 {
              contractAddress
              withdrawThreshold
              lifetimeLimit
            }
          }
        }
        ... on UpdateNetworkParameter {
          networkParameter {
            key
            value
          }
        }
        ... on UpdateAsset {
          quantum
          assetId
          source {
            ... on UpdateERC20 {
              lifetimeLimit
              withdrawThreshold
            }
          }
        }
      }
    }
    votes {
      yes {
        totalTokens
        totalNumber
        totalEquityLikeShareWeight
      }
      no {
        totalTokens
        totalNumber
        totalEquityLikeShareWeight
      }
    }
  }
`;
export const ProposalsDocument = gql`
  query Proposals {
    proposalsConnection {
      edges {
        node {
          ...ProposalFields
        }
      }
    }
  }
  ${ProposalFieldsFragmentDoc}
`;

/**
 * __useProposalsQuery__
 *
 * To run a query within a React component, call `useProposalsQuery` and pass it any options that fit your needs.
 * When your component renders, `useProposalsQuery` returns an object from Apollo Client that contains loading, error, and data properties
 * you can use to render your UI.
 *
 * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
 *
 * @example
 * const { data, loading, error } = useProposalsQuery({
 *   variables: {
 *   },
 * });
 */
export function useProposalsQuery(
  baseOptions?: Apollo.QueryHookOptions<ProposalsQuery, ProposalsQueryVariables>
) {
  const options = { ...defaultOptions, ...baseOptions };
  return Apollo.useQuery<ProposalsQuery, ProposalsQueryVariables>(
    ProposalsDocument,
    options
  );
}
export function useProposalsLazyQuery(
  baseOptions?: Apollo.LazyQueryHookOptions<
    ProposalsQuery,
    ProposalsQueryVariables
  >
) {
  const options = { ...defaultOptions, ...baseOptions };
  return Apollo.useLazyQuery<ProposalsQuery, ProposalsQueryVariables>(
    ProposalsDocument,
    options
  );
}
export type ProposalsQueryHookResult = ReturnType<typeof useProposalsQuery>;
export type ProposalsLazyQueryHookResult = ReturnType<
  typeof useProposalsLazyQuery
>;
export type ProposalsQueryResult = Apollo.QueryResult<
  ProposalsQuery,
  ProposalsQueryVariables
>;
