"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.RebaseChangesetConflictArgs = void 0;
/** @packageDocumentation
 * @module iModels
 */
const core_bentley_1 = require("@itwin/core-bentley");
const SqliteChangesetReader_1 = require("../SqliteChangesetReader");
class RebaseChangesetConflictArgs {
    _dbConflictArg;
    _iModel;
    constructor(_dbConflictArg, _iModel) {
        this._dbConflictArg = _dbConflictArg;
        this._iModel = _iModel;
    }
    get cause() {
        switch (this._dbConflictArg.cause) {
            case core_bentley_1.DbConflictCause.Conflict: return "Conflict";
            case core_bentley_1.DbConflictCause.Data: return "Data";
            case core_bentley_1.DbConflictCause.Constraint: return "Constraint";
            case core_bentley_1.DbConflictCause.ForeignKey: return "ForeignKey";
            case core_bentley_1.DbConflictCause.NotFound: return "NotFound";
        }
        throw new Error("Invalid value for cause");
    }
    get opcode() {
        switch (this._dbConflictArg.opcode) {
            case core_bentley_1.DbOpcode.Insert: return "Inserted";
            case core_bentley_1.DbOpcode.Update: return "Updated";
            case core_bentley_1.DbOpcode.Delete: return "Deleted";
        }
    }
    openTxn() {
        return SqliteChangesetReader_1.SqliteChangesetReader.openTxn({ txnId: this._dbConflictArg.txn.id, db: this._iModel });
    }
    get indirect() {
        return this._dbConflictArg.indirect;
    }
    get tableName() {
        return this._dbConflictArg.tableName;
    }
    get columnCount() {
        return this._dbConflictArg.columnCount;
    }
    getForeignKeyConflicts() {
        return this._dbConflictArg.getForeignKeyConflicts();
    }
    setLastError(message) {
        this._dbConflictArg.setLastError(message);
    }
    getPrimaryKeyColumns() {
        return this._dbConflictArg.getPrimaryKeyColumns();
    }
    getValueType(columnIndex, stage) {
        return this._dbConflictArg.getValueType(columnIndex, stage === "New" ? core_bentley_1.DbChangeStage.New : core_bentley_1.DbChangeStage.Old);
    }
    getValueBinary(columnIndex, stage) {
        return this._dbConflictArg.getValueBinary(columnIndex, stage === "New" ? core_bentley_1.DbChangeStage.New : core_bentley_1.DbChangeStage.Old);
    }
    getValueId(columnIndex, stage) {
        return this._dbConflictArg.getValueId(columnIndex, stage === "New" ? core_bentley_1.DbChangeStage.New : core_bentley_1.DbChangeStage.Old);
    }
    getValueText(columnIndex, stage) {
        return this._dbConflictArg.getValueText(columnIndex, stage === "New" ? core_bentley_1.DbChangeStage.New : core_bentley_1.DbChangeStage.Old);
    }
    getValueInteger(columnIndex, stage) {
        return this._dbConflictArg.getValueInteger(columnIndex, stage === "New" ? core_bentley_1.DbChangeStage.New : core_bentley_1.DbChangeStage.Old);
    }
    getValueDouble(columnIndex, stage) {
        return this._dbConflictArg.getValueDouble(columnIndex, stage === "New" ? core_bentley_1.DbChangeStage.New : core_bentley_1.DbChangeStage.Old);
    }
    isValueNull(columnIndex, stage) {
        return this._dbConflictArg.isValueNull(columnIndex, stage === "New" ? core_bentley_1.DbChangeStage.New : core_bentley_1.DbChangeStage.Old);
    }
    getColumnNames() {
        return this._dbConflictArg.getColumnNames();
    }
    getPrimaryKeyValues() {
        const pkv = [];
        if (this.opcode === undefined)
            return pkv;
        const stage = this._dbConflictArg.opcode === core_bentley_1.DbOpcode.Insert ? core_bentley_1.DbChangeStage.New : core_bentley_1.DbChangeStage.Old;
        for (const pk of this._dbConflictArg.getPrimaryKeyColumns()) {
            const type = this._dbConflictArg.getValueType(pk, stage);
            if (type === core_bentley_1.DbValueType.IntegerVal)
                pkv.push(this._dbConflictArg.getValueId(pk, stage));
            else if (type === core_bentley_1.DbValueType.TextVal)
                pkv.push(this._dbConflictArg.getValueText(pk, stage));
            else if (type === core_bentley_1.DbValueType.FloatVal)
                pkv.push(this._dbConflictArg.getValueDouble(pk, stage));
            else if (type === core_bentley_1.DbValueType.BlobVal)
                pkv.push(this._dbConflictArg.getValueBinary(pk, stage));
            else
                pkv.push(null);
        }
        return pkv;
    }
    ;
    get txn() {
        return this._dbConflictArg.txn;
    }
}
exports.RebaseChangesetConflictArgs = RebaseChangesetConflictArgs;
//# sourceMappingURL=ChangesetConflictArgs.js.map