/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the "Elastic License
 * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
 * Public License v 1"; you may not use this file except in compliance with, at
 * your election, the "Elastic License 2.0", the "GNU Affero General Public
 * License v3.0 only", or the "Server Side Public License, v 1".
 */

package org.elasticsearch.index.mapper;

import org.elasticsearch.index.mapper.NumberFieldMapper.NumberType;
import org.elasticsearch.xcontent.XContentBuilder;
import org.junit.AssumptionViolatedException;

import java.io.IOException;
import java.util.List;

public class ShortFieldMapperTests extends WholeNumberFieldMapperTests {

    @Override
    protected Number missingValue() {
        return 123;
    }

    @Override
    protected List<NumberTypeOutOfRangeSpec> outOfRangeSpecs() {
        return List.of(
            NumberTypeOutOfRangeSpec.of(NumberType.SHORT, "32768", "is out of range for a short"),
            NumberTypeOutOfRangeSpec.of(NumberType.SHORT, "-32769", "is out of range for a short"),
            NumberTypeOutOfRangeSpec.of(NumberType.SHORT, 32768, "out of range of Java short"),
            NumberTypeOutOfRangeSpec.of(NumberType.SHORT, -32769, "out of range of Java short")
        );
    }

    @Override
    protected void minimalMapping(XContentBuilder b) throws IOException {
        b.field("type", "short");
    }

    @Override
    protected Number randomNumber() {
        if (randomBoolean()) {
            return randomShort();
        }
        if (randomBoolean()) {
            return randomDouble();
        }
        return randomDoubleBetween(Short.MIN_VALUE, Short.MAX_VALUE, true);
    }

    @Override
    protected IngestScriptSupport ingestScriptSupport() {
        throw new AssumptionViolatedException("not supported");
    }
}
