// @flow

// ========= Response Types =========
export type AdaAssurance = 'CWANormal' | 'CWAStrict';
export type AdaTransactionCondition = 'CPtxApplying' | 'CPtxInBlocks' | 'CPtxWontApply' | 'CPtxNotTracked';
export type AdaWalletRecoveryPhraseResponse = Array<string>;
export type AdaWalletCertificateAdditionalMnemonicsResponse = Array<string>;
export type AdaWalletCertificateRecoveryPhraseResponse = Array<string>;
export type AdaWalletRecoveryPhraseFromCertificateResponse = Array<string>;
export type GetWalletCertificateAdditionalMnemonicsResponse = Array<string>;
export type GetWalletCertificateRecoveryPhraseResponse = Array<string>;
export type GetWalletRecoveryPhraseFromCertificateResponse = Array<string>;

export type AdaSyncProgressResponse = {
  _spLocalCD: {
    getChainDifficulty: {
      getBlockCount: number,
    }
  },
  _spNetworkCD: {
    getChainDifficulty: {
      getBlockCount: number,
    }
  },
  _spPeers: number,
};

export type AdaWalletInitData = {
  cwInitMeta: {
    cwName: string,
    cwAssurance: AdaAssurance,
    cwUnit: number,
  },
  cwBackupPhrase: {
    bpToList: [],
  }
};

export type AdaAmount = {
  getCCoin: number,
};
export type AdaTransactionTag = 'CTIn' | 'CTOut';

export type AdaAddress = {
  cadAmount: AdaAmount,
  cadId: string,
  cadIsUsed: boolean,
};

export type AdaAddresses = Array<AdaAddress>;

export type AdaAccount = {
  caAddresses: AdaAddresses,
  caAmount: AdaAmount,
  caId: string,
  caMeta: {
    caName: string,
  },
};

export type AdaAccountV1 = {
  data: [
    {
      amount: number,
      addresses: [
        {
          used: boolean,
          changeAddress: boolean,
          id: string
        }
      ],
      name: string,
      walletId: string,
      index: number
    }
  ],
  status: string,
  meta: {
    pagination: {
      totalPages: number,
      page: number,
      perPage: number,
      totalEntries: number,
    }
  }
};

export type AdaAccounts = Array<AdaAccount>;

export type AdaTransaction = {
  ctAmount: AdaAmount,
  ctConfirmations: number,
  ctId: string,
  ctInputs: AdaTransactionInputOutput,
  ctIsOutgoing: boolean,
  ctMeta: {
    ctmDate: Date,
    ctmDescription: ?string,
    ctmTitle: ?string,
  },
  ctOutputs: AdaTransactionInputOutput,
  ctCondition: AdaTransactionCondition,
};

export type AdaTransactions = [
  Array<AdaTransaction>,
  number,
];

export type AdaTransactionInputOutput = [
  [string, AdaAmount],
];

export type AdaTransactionFee = AdaAmount;

export type AdaWallet = {
  cwAccountsNumber: number,
  cwAmount: AdaAmount,
  cwHasPassphrase: boolean,
  cwId: string,
  cwMeta: {
    cwAssurance: AdaAssurance,
    cwName: string,
    csUnit: number,
  },
  cwPassphraseLU: Date,
};

export type AdaWallets = Array<AdaWallet>;

export type AdaLocalTimeDifference = number;


// ========== V1 API =========

export type AdaV1Assurance = 'normal' | 'strict';
export type AdaV1WalletSyncStateTag = 'restoring' | 'synced';

export type AdaV1WalletSyncState = {
  data: ?{
    estimatedCompletionTime: {
      quantity: number,
      unit: 'milliseconds',
    },
    percentage: {
      quantity: number,
      unit: 'percenage',
    },
    throughput: {
      quantity: number,
      unit: 'blocksPerSecond',
    },
  },
  tag: AdaV1WalletSyncStateTag,
};

export type AdaV1Wallet = {
  assuranceLevel: AdaV1Assurance,
  balance: number,
  createdAt: string,
  hasSpendingPassword: boolean,
  id: string,
  name: string,
  spendingPasswordLastUpdate: string,
  syncState: AdaV1WalletSyncState,
};

export type AdaV1Wallets = Array<AdaV1Wallet>;

export const AdaV1AssuranceOptions: {
  NORMAL: AdaV1Assurance, STRICT: AdaV1Assurance,
} = {
  NORMAL: 'normal', STRICT: 'strict',
};

@@ -1166,16 +1166,17 @@
 ber,%0A%7D;%0A
+%0A
 export t
@@ -2331,163 +2331,737 @@
 tion
-s = %5B%0A  Array%3CAdaTransaction%3E,%0A  number,%0A%5D;%0A%0Aexport type AdaTransactionInputOutput = %5B%0A  %5Bstring, AdaAmount%5D,%0A%5D;%0A%0Aexport type AdaTransactionFee = AdaAmount
+V1 = %7B%0A  amount: 28311699119270856,%0A  confirmations: number,%0A  creationTime: Date,%0A  direction: 'outgoing' %7C 'incoming',%0A  id: string,%0A  type: 'local' %7C 'foreign',%0A  inputs: AdaTransactionInputOutputV1,%0A  outputs: AdaTransactionInputOutputV1,%0A  status: %7B%0A    tag: 'applying' %7C 'inNewestBlocks' %7C 'persisted' %7C 'wontApply' %7C 'creating',%0A    data: %7B%7D,%0A  %7D,%0A%7D;%0A%0Aexport type AdaTransactions = %5B%0A  Array%3CAdaTransaction%3E,%0A  number,%0A%5D;%0A%0Aexport type AdaTransactionInputOutput = %5B%0A  %5Bstring, AdaAmount%5D,%0A%5D;%0A%0Aexport type AdaTransactionInputOutputV1 = %5B%0A  %5Bstring, number%5D,%0A%5D;%0A%0Aexport type AdaTransactionFee = AdaAmount;%0A%0Aexport type AdaTransactionFeeV1 = %7B%0A  estimatedAmount: number,%0A  status: %22success%22,%0A  meta: %7B%0A    pagination: %7B%7D%0A  %7D%0A%7D
 ;%0A%0Ae

Revert Types to current state