"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createVenue = exports.prepareCreateVenue = exports.createCreateVenueResolver = void 0;
const internal_1 = require("../../internal");
const types_1 = require("../../types");
const conversion_1 = require("../../utils/conversion");
const internal_2 = require("../../utils/internal");
/**
 * @hidden
 */
const createCreateVenueResolver = (context) => (receipt) => {
    const [{ data }] = (0, internal_2.filterEventRecords)(receipt, 'settlement', 'VenueCreated');
    const id = (0, conversion_1.u64ToBigNumber)(data[1]);
    return new internal_1.Venue({ id }, context);
};
exports.createCreateVenueResolver = createCreateVenueResolver;
/**
 * @hidden
 */
function prepareCreateVenue(args) {
    return __awaiter(this, void 0, void 0, function* () {
        const { context: { polymeshApi: { tx: { settlement }, }, }, context, } = this;
        const { description, type } = args;
        const rawDetails = (0, conversion_1.stringToBytes)(description, context);
        const rawType = (0, conversion_1.venueTypeToMeshVenueType)(type, context);
        // NOTE @monitz87: we're sending an empty signer array for the moment
        const [newVenue] = this.addTransaction({
            transaction: settlement.createVenue,
            resolvers: [(0, exports.createCreateVenueResolver)(context)],
            args: [rawDetails, [], rawType],
        });
        return newVenue;
    });
}
exports.prepareCreateVenue = prepareCreateVenue;
/**
 * @hidden
 */
const createVenue = () => new internal_1.Procedure(prepareCreateVenue, {
    permissions: {
        transactions: [types_1.TxTags.settlement.CreateVenue],
        assets: [],
        portfolios: [],
    },
});
exports.createVenue = createVenue;
//# sourceMappingURL=createVenue.js.map