"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContractStartGen = void 0;
const generator_1 = require("../generator");
const utils_1 = require("../utils");
const types_1 = require("../../types");
class ContractStartGen {
    gen(schema) {
        let inheritance = this.getBaseInheritance(schema.features);
        if (schema.hasLiteRef()) {
            inheritance.push("PatchworkLiteRef");
        }
        if (schema.features.some((feature) => feature === types_1.Feature.MINTABLE)) {
            inheritance.push("IPatchworkMintable");
        }
        let out = `abstract contract ${(0, utils_1.cleanAndCapitalizeFirstLetter)(schema.name)}Generated is ${inheritance.join(", ")} {\n`;
        if (schema.hasLiteRef()) {
            out += `\n`;
            if (schema.liteRefArrayLength(0) == 0) {
                out += (0, generator_1.ind)(4, `error AlreadyLoaded();\nerror NotFound();\nerror StorageIntegrityError();\nerror UnsupportedMetadataId();\n`);
            }
            else if (schema.liteRefArrayLength(0) == 1) {
                out += (0, generator_1.ind)(4, `error NoReferenceSlotsAvailable();\nerror TooManyReferences();\nerror NoReference();\nerror UnsupportedMetadataId();\n`);
            }
            else {
                out += (0, generator_1.ind)(4, `error NoReferenceSlotsAvailable();\nerror TooManyReferences();\nerror NoReference();\nerror UnsupportedMetadataId();\nerror AlreadyHaveReferences();\n`);
            }
        }
        return out;
    }
    getBaseInheritance(features) {
        let inheritance = [];
        if (features.some((feature) => feature === types_1.Feature.PATCH)) {
            inheritance.push(`PatchworkPatch`);
        }
        if (features.some((feature) => feature === types_1.Feature.PATCH1155)) {
            inheritance.push(`Patchwork1155Patch`);
        }
        if (features.some((feature) => feature === types_1.Feature.PATCHACCOUNT)) {
            inheritance.push(`PatchworkAccountPatch`);
        }
        if (features.some((feature) => feature === types_1.Feature.FRAGMENTMULTI)) {
            inheritance.push(`PatchworkFragmentMulti`);
        }
        if (features.some((feature) => feature === types_1.Feature.FRAGMENTSINGLE)) {
            inheritance.push(`PatchworkFragmentSingle`);
        }
        // If no specific feature is found, default to Patchwork721
        if (inheritance.length === 0) {
            inheritance.push(`Patchwork721`);
        }
        return inheritance;
    }
}
exports.ContractStartGen = ContractStartGen;
