import { SYSTEM_PROGRAM_ADDRESS } from '../constants.js';
import { ByteCursor, concatBytes, u8 } from '../codecs/binary.js';
import { deriveTestIsmStoragePda } from '../pda.js';
import { buildInstruction, readonlyAccount, writableAccount, writableSigner, } from './utils.js';
export var TestIsmInstructionKind;
(function (TestIsmInstructionKind) {
    TestIsmInstructionKind[TestIsmInstructionKind["Init"] = 0] = "Init";
    TestIsmInstructionKind[TestIsmInstructionKind["SetAccept"] = 1] = "SetAccept";
})(TestIsmInstructionKind || (TestIsmInstructionKind = {}));
export function encodeTestIsmProgramInstruction(instruction) {
    switch (instruction.kind) {
        case 'init':
            return u8(TestIsmInstructionKind.Init);
        case 'setAccept':
            return concatBytes(u8(TestIsmInstructionKind.SetAccept), u8(instruction.accept ? 1 : 0));
    }
}
export function decodeTestIsmProgramInstruction(data) {
    if (data.length < 1)
        return null;
    const cursor = new ByteCursor(data);
    const kind = cursor.readU8();
    switch (kind) {
        case TestIsmInstructionKind.Init:
            return { kind: 'init' };
        case TestIsmInstructionKind.SetAccept:
            return { kind: 'setAccept', accept: cursor.readBool() };
        default:
            if (kind <= TestIsmInstructionKind.SetAccept) {
                throw new Error(`TestIsm instruction kind ${kind} is recognized but decoding is not yet implemented`);
            }
            return null;
    }
}
export async function getInitTestIsmInstruction(programAddress, payer) {
    const { address: storage } = await deriveTestIsmStoragePda(programAddress);
    return buildInstruction(programAddress, [
        readonlyAccount(SYSTEM_PROGRAM_ADDRESS),
        writableSigner(payer),
        writableAccount(storage),
    ], encodeTestIsmProgramInstruction({ kind: 'init' }));
}
export async function getSetAcceptTestIsmInstruction(programAddress, accept) {
    const { address: storage } = await deriveTestIsmStoragePda(programAddress);
    return buildInstruction(programAddress, [writableAccount(storage)], encodeTestIsmProgramInstruction({ kind: 'setAccept', accept }));
}
//# sourceMappingURL=test-ism.js.map