// SPDX-License-Identifier: Apache-2.0
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { OptionalField } from '../../../../core/decorator/OptionalDecorator';
import { Security } from '../../../../domain/context/security/Security';
import ValidatedRequest from '../../../../core/validation/ValidatedArgs';
import FormatValidation from '../FormatValidation';
import { SecurityDate } from '../../../../domain/context/shared/SecurityDate';
import { Factory } from '../../../../domain/context/factory/Factories';
import { InvalidValue } from '../error/InvalidValue';
export default class CreateBondRequest extends ValidatedRequest {
    get decimals() {
        return this._decimals;
    }
    set decimals(value) {
        this._decimals = typeof value === 'number' ? value : parseFloat(value);
    }
    constructor({ name, symbol, isin, decimals, isWhiteList, erc20VotesActivated, isControllable, arePartitionsProtected, isMultiPartition, clearingActive, internalKycActivated, externalPausesIds, externalControlListsIds, externalKycListsIds, diamondOwnerAccount, currency, numberOfUnits, nominalValue, nominalValueDecimals, startingDate, maturityDate, regulationType, regulationSubType, isCountryControlListWhiteList, countries, info, configId, configVersion, complianceId, identityRegistryId, proceedRecipientsIds, proceedRecipientsData, }) {
        super({
            name: (val) => {
                return Security.checkName(val);
            },
            symbol: (val) => {
                return Security.checkSymbol(val);
            },
            isin: (val) => {
                return Security.checkISIN(val);
            },
            decimals: (val) => {
                return Security.checkInteger(val);
            },
            diamondOwnerAccount: FormatValidation.checkHederaIdFormatOrEvmAddress(false),
            currency: FormatValidation.checkBytes3Format(),
            numberOfUnits: FormatValidation.checkNumber(),
            nominalValue: FormatValidation.checkNumber(),
            startingDate: (val) => {
                return SecurityDate.checkDateTimestamp(parseInt(val), Math.ceil(new Date().getTime() / 1000), parseInt(this.maturityDate));
            },
            maturityDate: (val) => {
                return SecurityDate.checkDateTimestamp(parseInt(val), parseInt(this.startingDate), undefined);
            },
            regulationType: (val) => {
                return Factory.checkRegulationType(val);
            },
            regulationSubType: (val) => {
                return Factory.checkRegulationSubType(val, this.regulationType);
            },
            configId: FormatValidation.checkBytes32Format(),
            externalPausesIds: (val) => {
                return FormatValidation.checkHederaIdOrEvmAddressArray(val ?? [], 'externalPausesIds', true);
            },
            externalControlListsIds: (val) => {
                return FormatValidation.checkHederaIdOrEvmAddressArray(val ?? [], 'externalControlListsIds', true);
            },
            externalKycListsIds: (val) => {
                return FormatValidation.checkHederaIdOrEvmAddressArray(val ?? [], 'externalKycListsIds', true);
            },
            complianceId: FormatValidation.checkHederaIdFormatOrEvmAddress(true),
            identityRegistryId: FormatValidation.checkHederaIdFormatOrEvmAddress(true),
            proceedRecipientsIds: (val) => {
                return FormatValidation.checkHederaIdOrEvmAddressArray(val ?? [], 'proceedRecipientsIds', true);
            },
            proceedRecipientsData: (val) => {
                const validation = FormatValidation.checkBytesFormat();
                if (val?.length != this.proceedRecipientsIds?.length) {
                    return [
                        new InvalidValue(`The list of proceedRecipientsIds and proceedRecipientsData must have equal length.`),
                    ];
                }
                for (const data of val ?? []) {
                    if (data == '')
                        continue;
                    const result = validation(data);
                    if (result)
                        return result;
                }
            },
        });
        this.name = name;
        this.symbol = symbol;
        this.isin = isin;
        this.decimals =
            typeof decimals === 'number' ? decimals : parseInt(decimals);
        this.isWhiteList = isWhiteList;
        this.erc20VotesActivated = erc20VotesActivated;
        this.isControllable = isControllable;
        this.arePartitionsProtected = arePartitionsProtected;
        this.isMultiPartition = isMultiPartition;
        this.clearingActive = clearingActive;
        this.internalKycActivated = internalKycActivated;
        this.diamondOwnerAccount = diamondOwnerAccount;
        this.externalPausesIds = externalPausesIds;
        this.externalControlListsIds = externalControlListsIds;
        this.externalKycListsIds = externalKycListsIds;
        this.currency = currency;
        this.numberOfUnits = numberOfUnits;
        this.nominalValue = nominalValue;
        this.nominalValueDecimals = nominalValueDecimals;
        this.startingDate = startingDate;
        this.maturityDate = maturityDate;
        this.regulationType = regulationType;
        this.regulationSubType = regulationSubType;
        this.isCountryControlListWhiteList = isCountryControlListWhiteList;
        this.countries = countries;
        this.info = info;
        this.configId = configId;
        this.configVersion = configVersion;
        this.complianceId = complianceId;
        this.identityRegistryId = identityRegistryId;
        this.proceedRecipientsIds = proceedRecipientsIds;
        this.proceedRecipientsData = proceedRecipientsData;
    }
}
__decorate([
    OptionalField(),
    __metadata("design:type", Array)
], CreateBondRequest.prototype, "externalPausesIds", void 0);
__decorate([
    OptionalField(),
    __metadata("design:type", Array)
], CreateBondRequest.prototype, "externalControlListsIds", void 0);
__decorate([
    OptionalField(),
    __metadata("design:type", Array)
], CreateBondRequest.prototype, "externalKycListsIds", void 0);
__decorate([
    OptionalField(),
    __metadata("design:type", String)
], CreateBondRequest.prototype, "diamondOwnerAccount", void 0);
__decorate([
    OptionalField(),
    __metadata("design:type", String)
], CreateBondRequest.prototype, "complianceId", void 0);
__decorate([
    OptionalField(),
    __metadata("design:type", String)
], CreateBondRequest.prototype, "identityRegistryId", void 0);
__decorate([
    OptionalField(),
    __metadata("design:type", Array)
], CreateBondRequest.prototype, "proceedRecipientsIds", void 0);
__decorate([
    OptionalField(),
    __metadata("design:type", Array)
], CreateBondRequest.prototype, "proceedRecipientsData", void 0);
