import { MySBTABI, ReputationSystemABI } from './chunk-ZSSNU3UF.js';
import { parseAbi } from 'viem';

// ../identity/dist/mysbt.js
async function checkMySBT(client, sbtAddress, user) {
  const balance = await client.readContract({
    address: sbtAddress,
    abi: MySBTABI,
    functionName: "balanceOf",
    args: [user]
  });
  return { hasSBT: balance > 0n, balance };
}
async function getMySBTId(client, sbtAddress, user) {
  const tokenId = await client.readContract({
    address: sbtAddress,
    abi: MySBTABI,
    functionName: "getUserSBT",
    args: [user]
  });
  return tokenId > 0n ? tokenId : null;
}
var ReputationClient = class {
  client;
  reputationAddress;
  /** @internal */
  walletClient;
  /**
   * Initialize ReputationClient
   * @param client The public client for queries
   * @param reputationAddress The address of the reputation system contract
   * @param walletClient Optional wallet client for write operations
   */
  constructor(client, reputationAddress, walletClient) {
    this.client = client;
    this.reputationAddress = reputationAddress;
    this.walletClient = walletClient;
  }
  /**
   * Compute reputation score for a user
   */
  async computeScore(user, communities, ruleIds, activities) {
    return this.client.readContract({
      address: this.reputationAddress,
      abi: ReputationSystemABI,
      functionName: "computeScore",
      args: [user, communities, ruleIds, activities]
    });
  }
  /**
   * Get global reputation score for a user
   * @param user User address
   * @returns Reputation score
   */
  async getGlobalReputation(user) {
    try {
      const score = await this.computeScore(user, [], [], []);
      return Number(score);
    } catch (e) {
      console.warn("Failed to read reputation from contract, defaulting to 0");
      return 0;
    }
  }
  /**
   * Get credit limit based on reputation
   * @param user User address
   * @returns Credit limit in wei (Mock logic closely tied to Reputation)
   */
  async getCreditLimit(user) {
    const reputation = await this.getGlobalReputation(user);
    let limit = 0n;
    if (reputation > 50)
      limit += 10000000000000000n;
    if (reputation > 100)
      limit += 40000000000000000n;
    return limit;
  }
  /**
   * Get reputation score breakdown
   * @param user User address
   * @returns Detailed reputation breakdown (Mock implementation awaiting contract V4)
   */
  async getReputationBreakdown(user) {
    const total = await this.getGlobalReputation(user);
    return {
      baseScore: Math.floor(total * 0.5),
      stakingBonus: Math.floor(total * 0.3),
      activityBonus: Math.floor(total * 0.2),
      penaltyDeduction: 0,
      total
    };
  }
  /**
   * Submit reputation proof (off-chain data to on-chain)
   * @param params Proof parameters
   * @returns Transaction hash
   */
  async submitReputationProof(params) {
    if (!this.walletClient || !this.walletClient.account) {
      throw new Error("Wallet client required to submit proofs");
    }
    return this.walletClient.writeContract({
      address: this.reputationAddress,
      abi: parseAbi(["function submitProof(string,bytes32)"]),
      functionName: "submitProof",
      args: [params.proofData, params.signature],
      chain: this.walletClient.chain,
      account: this.walletClient.account
    });
  }
};

export { ReputationClient, checkMySBT, getMySBTId };
//# sourceMappingURL=chunk-NZGXB2C5.js.map
//# sourceMappingURL=chunk-NZGXB2C5.js.map