import { __decorate, __metadata } from "tslib";
import { GrumpkinAddress } from '@polyaztec/barretenberg/address';
import { TreeNote } from '@polyaztec/barretenberg/note_algorithms';
import { AfterInsert, AfterLoad, AfterUpdate, Column, Entity, Index, PrimaryColumn } from 'typeorm';
import { Note } from '../../note/index.js';
import { bigintTransformer, grumpkinAddressTransformer } from './transformer.js';
let NoteDao = class NoteDao {
    afterLoad() {
        if (!this.hashPath) {
            delete this.hashPath;
        }
        if (this.index === null) {
            delete this.index;
        }
    }
};
__decorate([
    PrimaryColumn(),
    __metadata("design:type", Buffer)
], NoteDao.prototype, "commitment", void 0);
__decorate([
    Index({ unique: true }),
    Column(),
    __metadata("design:type", Buffer)
], NoteDao.prototype, "nullifier", void 0);
__decorate([
    Column(),
    __metadata("design:type", Buffer)
], NoteDao.prototype, "noteSecret", void 0);
__decorate([
    Column('blob', { transformer: [grumpkinAddressTransformer] }),
    __metadata("design:type", GrumpkinAddress)
], NoteDao.prototype, "owner", void 0);
__decorate([
    Column(),
    __metadata("design:type", Boolean)
], NoteDao.prototype, "accountRequired", void 0);
__decorate([
    Column(),
    __metadata("design:type", Buffer)
], NoteDao.prototype, "creatorPubKey", void 0);
__decorate([
    Column(),
    __metadata("design:type", Buffer)
], NoteDao.prototype, "inputNullifier", void 0);
__decorate([
    Column(),
    __metadata("design:type", Number)
], NoteDao.prototype, "assetId", void 0);
__decorate([
    Column('text', { transformer: [bigintTransformer] }),
    __metadata("design:type", typeof BigInt === "function" ? BigInt : Object)
], NoteDao.prototype, "value", void 0);
__decorate([
    Column(),
    __metadata("design:type", Boolean)
], NoteDao.prototype, "allowChain", void 0);
__decorate([
    Index({ unique: false }),
    Column({ nullable: true }),
    __metadata("design:type", Number)
], NoteDao.prototype, "index", void 0);
__decorate([
    Index({ unique: false }),
    Column(),
    __metadata("design:type", Boolean)
], NoteDao.prototype, "nullified", void 0);
__decorate([
    Column({ nullable: true }),
    __metadata("design:type", Buffer)
], NoteDao.prototype, "hashPath", void 0);
__decorate([
    AfterLoad(),
    AfterInsert(),
    AfterUpdate(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], NoteDao.prototype, "afterLoad", null);
NoteDao = __decorate([
    Entity({ name: 'note' })
], NoteDao);
export { NoteDao };
export const noteToNoteDao = ({ treeNote: { noteSecret, ownerPubKey, accountRequired, creatorPubKey, inputNullifier, assetId }, commitment, nullifier, value, allowChain, index, nullified, hashPath, }) => ({
    commitment,
    nullifier,
    noteSecret,
    owner: ownerPubKey,
    accountRequired,
    creatorPubKey,
    inputNullifier,
    assetId,
    value,
    allowChain,
    nullified,
    index,
    hashPath,
});
export const noteDaoToNote = ({ commitment, nullifier, noteSecret, owner, accountRequired, creatorPubKey, inputNullifier, assetId, value, allowChain, index, nullified, hashPath, }) => new Note(new TreeNote(owner, value, assetId, accountRequired, noteSecret, creatorPubKey, inputNullifier), commitment, nullifier, allowChain, nullified, index, hashPath);
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibm90ZV9kYW8uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvZGF0YWJhc2Uvbm9kZS9ub3RlX2Rhby50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsT0FBTyxFQUFFLGVBQWUsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBQ2xFLE9BQU8sRUFBRSxRQUFRLEVBQUUsTUFBTSx5Q0FBeUMsQ0FBQztBQUNuRSxPQUFPLEVBQUUsV0FBVyxFQUFFLFNBQVMsRUFBRSxXQUFXLEVBQUUsTUFBTSxFQUFFLE1BQU0sRUFBRSxLQUFLLEVBQUUsYUFBYSxFQUFFLE1BQU0sU0FBUyxDQUFDO0FBQ3BHLE9BQU8sRUFBRSxJQUFJLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUMzQyxPQUFPLEVBQUUsaUJBQWlCLEVBQUUsMEJBQTBCLEVBQ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