// Code generated by bitwrap synth; DO NOT EDIT.
// Source schema: ERC05725 ERC-05725:1.0.0

package prover

import (
	"github.com/consensys/gnark/frontend"
)

// VestingClaimCircuit is generated from schema action "claim". Parity target: VestingClaimCircuit in prover/circuits.go.
type VestingClaimCircuit struct {
	PreStateRoot  frontend.Variable `gnark:",public"`
	PostStateRoot frontend.Variable `gnark:",public"`
	TokenID       frontend.Variable `gnark:",public"`
	Caller        frontend.Variable `gnark:",public"`
	ClaimAmount   frontend.Variable `gnark:",public"`

	VestedAmount frontend.Variable
	Claimed      frontend.Variable
	Owner        frontend.Variable

	SchedulePath    [10]frontend.Variable
	ScheduleIndices [10]frontend.Variable
	OwnerPath       [10]frontend.Variable
	OwnerIndices    [10]frontend.Variable
}

func (c *VestingClaimCircuit) Define(api frontend.API) error {
	// Role check (Action.Roles contains "owner")
	api.AssertIsEqual(c.Owner, c.Caller)

	// Range check: available - claimAmount >= 0, 64 bits
	available := api.Sub(c.VestedAmount, c.Claimed)
	diff := api.Sub(available, c.ClaimAmount)
	api.ToBinary(diff, 64)

	// Schedule Merkle proof
	scheduleLeaf := synthMimcHash(api, c.TokenID, c.VestedAmount)
	current := scheduleLeaf
	for i := 0; i < 10; i++ {
		api.AssertIsBoolean(c.ScheduleIndices[i])
		left := api.Select(c.ScheduleIndices[i], c.SchedulePath[i], current)
		right := api.Select(c.ScheduleIndices[i], current, c.SchedulePath[i])
		current = synthMimcHash(api, left, right)
	}
	scheduleRoot := current

	// Owner Merkle proof
	ownerLeaf := synthMimcHash(api, c.TokenID, c.Owner)
	current = ownerLeaf
	for i := 0; i < 10; i++ {
		api.AssertIsBoolean(c.OwnerIndices[i])
		left := api.Select(c.OwnerIndices[i], c.OwnerPath[i], current)
		right := api.Select(c.OwnerIndices[i], current, c.OwnerPath[i])
		current = synthMimcHash(api, left, right)
	}
	ownerRoot := current

	// Composite pre-state root
	computedRoot := synthMimcHash(api, scheduleRoot, ownerRoot)
	api.AssertIsEqual(computedRoot, c.PreStateRoot)

	// Post-state: claimed[tokenId] += claimAmount
	newClaimed := api.Add(c.Claimed, c.ClaimAmount)
	postLeaf := synthMimcHash(api, c.TokenID, newClaimed)
	api.AssertIsEqual(postLeaf, c.PostStateRoot)
	return nil
}
