"""PDA derivation matching pkg/realms/pda.go for the subset corpo needs."""

from solders.pubkey import Pubkey


def find_token_owner_record(
    program_id: Pubkey, realm: Pubkey, mint: Pubkey, owner: Pubkey
) -> tuple[Pubkey, int]:
    """Derive TokenOwnerRecord PDA.

    Seeds: ["governance", realm, mint, owner]
    """
    return Pubkey.find_program_address(
        [b"governance", bytes(realm), bytes(mint), bytes(owner)],
        program_id,
    )


def find_proposal_deposit(
    program_id: Pubkey, proposal: Pubkey, payer: Pubkey
) -> tuple[Pubkey, int]:
    """Derive ProposalDeposit PDA.

    Seeds: ["proposal-deposit", proposal, payer]
    """
    return Pubkey.find_program_address(
        [b"proposal-deposit", bytes(proposal), bytes(payer)],
        program_id,
    )


def find_proposal_address(
    program_id: Pubkey,
    governance: Pubkey,
    governing_token_mint: Pubkey,
    proposal_seed: Pubkey,
) -> tuple[Pubkey, int]:
    """Derive Proposal PDA.

    Seeds: ["governance", governance, governing_token_mint, proposal_seed]
    """
    return Pubkey.find_program_address(
        [
            b"governance",
            bytes(governance),
            bytes(governing_token_mint),
            bytes(proposal_seed),
        ],
        program_id,
    )


def find_vote_record_address(
    program_id: Pubkey, proposal: Pubkey, token_owner_record: Pubkey
) -> tuple[Pubkey, int]:
    """Derive VoteRecord PDA.

    Seeds: ["governance", proposal, token_owner_record]
    """
    return Pubkey.find_program_address(
        [b"governance", bytes(proposal), bytes(token_owner_record)],
        program_id,
    )
