// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.query.profile.compiled;

import com.yahoo.search.query.profile.DimensionValues;

import java.util.Optional;

/**
 * A value in a query profile with information about its source.
 *
 * @author bratseth
 */
public class ValueWithSource {

    private final Object value;

    /** The id of the query profile having a value */
    private final String ownerId;

    /** The dimension values specifying a variant in that profile, or null if it is not in a variant */
    private final DimensionValues variant;

    public ValueWithSource(Object value, String ownerId, DimensionValues variant) {
        this.value = value;
        this.ownerId = ownerId;
        this.variant = variant;
    }

    public Object value() { return value; }

    public String ownerId() { return ownerId; }

    public ValueWithSource withValue(Object value) {
        return new ValueWithSource(value, ownerId, variant);
    }

    /** Returns the variant having this value, or empty if it's not in a variant */
    public Optional<DimensionValues> variant() { return Optional.ofNullable(variant); }

    @Override
    public String toString() {
        return value +
               " (from query profile '" + ownerId + "'" +
               ( variant != null ? " variant " + variant : "") +
               ")";
    }

}

@@ -413,18 +413,22 @@
 /** The 
-id
+source
  of the 
@@ -489,18 +489,22 @@
 ng owner
-Id
+Source
 ;%0A%0A    /
@@ -699,18 +699,22 @@
 ng owner
-Id
+Source
 , Dimens
@@ -784,18 +784,22 @@
 wner
-Id
+Source
  = owner
 Id;%0A
@@ -794,18 +794,22 @@
  = owner
-Id
+Source
 ;%0A      
@@ -909,18 +909,22 @@
 ng owner
-Id
+Source
 () %7B ret
@@ -932,18 +932,22 @@
 rn owner
-Id
+Source
 ; %7D%0A%0A   
@@ -1043,18 +1043,22 @@
 e, owner
-Id
+Source
 , varian
@@ -1360,10 +1360,14 @@
 wner
-Id
+Source
  + %22

Rename ownerId to ownerSource