"use strict";
// SPDX-License-Identifier: Apache-2.0
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TrexClaimDetails = exports.TrexTokenDetailsAts = void 0;
const InvalidRequest_1 = require("../../../app/usecase/command/error/InvalidRequest");
const ValidatedArgs_1 = __importDefault(require("../../../core/validation/ValidatedArgs"));
class TrexTokenDetailsAts extends ValidatedArgs_1.default {
    owner;
    irs;
    onchainId;
    irAgents;
    tokenAgents;
    compliancesModules;
    complianceSettings;
    constructor(params) {
        super({
            irAgents: (val) => {
                return TrexTokenDetailsAts.checkMaxAgents(val, params.tokenAgents);
            },
            tokenAgents: (val) => {
                return TrexTokenDetailsAts.checkMaxAgents(params.irAgents, val);
            },
            compliancesModules: (val) => {
                return TrexTokenDetailsAts.checkComplianceModules(val, params.complianceSettings);
            },
            complianceSettings: (val) => {
                return TrexTokenDetailsAts.checkComplianceModules(params.compliancesModules, val);
            },
        });
        const { owner, irs, onchainId, irAgents = [], tokenAgents = [], compliancesModules = [], complianceSettings = [], } = params;
        this.owner = owner;
        this.irs = irs;
        this.onchainId = onchainId;
        this.irAgents = irAgents;
        this.tokenAgents = tokenAgents;
        this.compliancesModules = compliancesModules;
        this.complianceSettings = complianceSettings;
        ValidatedArgs_1.default.handleValidation(TrexTokenDetailsAts.name, this);
    }
    static checkMaxAgents(irAgents, tokenAgents) {
        const errorList = [];
        if (irAgents.length > 5 || tokenAgents.length > 5) {
            errorList.push(new InvalidRequest_1.InvalidRequest("max 5 agents at deployment"));
        }
        return errorList;
    }
    static checkComplianceModules(compliancesModules, complianceSettings) {
        const errorList = [];
        if (compliancesModules.length > 30) {
            errorList.push(new InvalidRequest_1.InvalidRequest("max 30 module actions at deployment"));
        }
        if (compliancesModules.length < complianceSettings.length) {
            errorList.push(new InvalidRequest_1.InvalidRequest("invalid compliance pattern"));
        }
        return errorList;
    }
}
exports.TrexTokenDetailsAts = TrexTokenDetailsAts;
class TrexClaimDetails extends ValidatedArgs_1.default {
    claimTopics;
    issuers;
    issuerClaims;
    constructor(params) {
        super({
            claimTopics: (val) => {
                return TrexClaimDetails.checkClaimTopics(val);
            },
            issuers: (val) => {
                return TrexClaimDetails.checkIssuers(val, params.issuerClaims);
            },
        });
        const { claimTopics = [], issuers = [], issuerClaims = [] } = params;
        this.claimTopics = claimTopics;
        this.issuers = issuers;
        this.issuerClaims = issuerClaims;
        ValidatedArgs_1.default.handleValidation(TrexClaimDetails.name, this);
    }
    static checkClaimTopics(value) {
        const errorList = [];
        if (value.length > 5) {
            errorList.push(new InvalidRequest_1.InvalidRequest("max 5 claim topics at deployment"));
        }
        return errorList;
    }
    static checkIssuers(issuers, issuerClaims) {
        const errorList = [];
        if (issuers.length > 5) {
            errorList.push(new InvalidRequest_1.InvalidRequest("max 5 claim issuers at deployment"));
        }
        if (issuers.length !== issuerClaims.length) {
            errorList.push(new InvalidRequest_1.InvalidRequest("claim pattern not valid"));
        }
        return errorList;
    }
}
exports.TrexClaimDetails = TrexClaimDetails;
