"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateGovernanceUploadPayload = validateGovernanceUploadPayload;
function isNonEmptyString(value) {
    return typeof value === 'string' && value.trim().length > 0;
}
function isFiniteNumber(value) {
    return typeof value === 'number' && Number.isFinite(value);
}
function validateGovernanceUploadPayload(payload) {
    const errors = [];
    if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
        return ['Payload must be an object.'];
    }
    const typed = payload;
    if (!isFiniteNumber(typed.schemaVersion)) {
        errors.push('schemaVersion must be a finite number.');
    }
    if (typed.uploadMode !== 'manual' && typed.uploadMode !== 'ci') {
        errors.push('uploadMode must be "manual" or "ci".');
    }
    const organization = typed.organization;
    const repository = typed.repository;
    const snapshot = typed.snapshot;
    const findings = typed.findings;
    const rawPayload = typed.rawPayload;
    if (!organization || typeof organization !== 'object' || Array.isArray(organization)) {
        errors.push('organization must be an object.');
    }
    else {
        if (!isNonEmptyString(organization.slug)) {
            errors.push('organization.slug must be a non-empty string.');
        }
        if (!isNonEmptyString(organization.name)) {
            errors.push('organization.name must be a non-empty string.');
        }
    }
    if (!repository || typeof repository !== 'object' || Array.isArray(repository)) {
        errors.push('repository must be an object.');
    }
    else {
        if (!isNonEmptyString(repository.externalRepositoryId)) {
            errors.push('repository.externalRepositoryId must be a non-empty string.');
        }
        if (!isNonEmptyString(repository.repositoryId)) {
            errors.push('repository.repositoryId must be a non-empty string.');
        }
        if (!isNonEmptyString(repository.name)) {
            errors.push('repository.name must be a non-empty string.');
        }
        if (!isNonEmptyString(repository.url)) {
            errors.push('repository.url must be a non-empty string.');
        }
        if (!isNonEmptyString(repository.defaultBranch)) {
            errors.push('repository.defaultBranch must be a non-empty string.');
        }
    }
    if (!snapshot || typeof snapshot !== 'object' || Array.isArray(snapshot)) {
        errors.push('snapshot must be an object.');
    }
    else {
        if (!isNonEmptyString(snapshot.commitSha)) {
            errors.push('snapshot.commitSha must be a non-empty string.');
        }
        if (!isNonEmptyString(snapshot.branch)) {
            errors.push('snapshot.branch must be a non-empty string.');
        }
        if (snapshot.source !== 'cli' && snapshot.source !== 'ci') {
            errors.push('snapshot.source must be "cli" or "ci".');
        }
        if (!isFiniteNumber(snapshot.architectureScore)) {
            errors.push('snapshot.architectureScore must be a finite number.');
        }
        if (!isFiniteNumber(snapshot.setupReadinessScore)) {
            errors.push('snapshot.setupReadinessScore must be a finite number.');
        }
        if (!isNonEmptyString(snapshot.changeRisk)) {
            errors.push('snapshot.changeRisk must be a non-empty string.');
        }
        if (!isNonEmptyString(snapshot.governanceRisk)) {
            errors.push('snapshot.governanceRisk must be a non-empty string.');
        }
        if (!isNonEmptyString(snapshot.enforcement)) {
            errors.push('snapshot.enforcement must be a non-empty string.');
        }
        const summary = snapshot.summary;
        if (!summary || typeof summary !== 'object' || Array.isArray(summary)) {
            errors.push('snapshot.summary must be an object.');
        }
        else {
            if (!isFiniteNumber(summary.modules)) {
                errors.push('snapshot.summary.modules must be a finite number.');
            }
            if (!isFiniteNumber(summary.violations)) {
                errors.push('snapshot.summary.violations must be a finite number.');
            }
        }
        const findingsCount = snapshot.findingsCount;
        if (!findingsCount || typeof findingsCount !== 'object' || Array.isArray(findingsCount)) {
            errors.push('snapshot.findingsCount must be an object.');
        }
        else {
            if (!isFiniteNumber(findingsCount.total)) {
                errors.push('snapshot.findingsCount.total must be a finite number.');
            }
            if (!isFiniteNumber(findingsCount.warning)) {
                errors.push('snapshot.findingsCount.warning must be a finite number.');
            }
            if (!isFiniteNumber(findingsCount.error)) {
                errors.push('snapshot.findingsCount.error must be a finite number.');
            }
        }
        const artifactMeta = snapshot.artifactMeta;
        if (!artifactMeta || typeof artifactMeta !== 'object' || Array.isArray(artifactMeta)) {
            errors.push('snapshot.artifactMeta must be an object.');
        }
        else if (!isNonEmptyString(artifactMeta.cliVersion)) {
            errors.push('snapshot.artifactMeta.cliVersion must be a non-empty string.');
        }
    }
    if (!Array.isArray(findings)) {
        errors.push('findings must be an array.');
    }
    if (!rawPayload || typeof rawPayload !== 'object' || Array.isArray(rawPayload)) {
        errors.push('rawPayload must be an object.');
    }
    return errors;
}
//# sourceMappingURL=governanceContracts.js.map