/* 
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

namespace ParquetSharp.Column.Page
{
    using ParquetSharp.Bytes;
    using ParquetSharp.Column.Statistics;

    public class DataPageV1 : DataPage
    {
        private readonly BytesInput bytes;
        private readonly Statistics statistics;
        private readonly Encoding rlEncoding;
        private readonly Encoding dlEncoding;
        private readonly Encoding valuesEncoding;

        /**
         * @param bytes the bytes for this page
         * @param valueCount count of values in this page
         * @param uncompressedSize the uncompressed size of the page
         * @param statistics of the page's values (max, min, num_null)
         * @param rlEncoding the repetition level encoding for this page
         * @param dlEncoding the definition level encoding for this page
         * @param valuesEncoding the values encoding for this page
         * @param dlEncoding
         */
        public DataPageV1(BytesInput bytes, int valueCount, int uncompressedSize, Statistics stats, Encoding rlEncoding, Encoding dlEncoding, Encoding valuesEncoding)
            : base(Ints.checkedCast(bytes.size()), uncompressedSize, valueCount)
        {
            this.bytes = bytes;
            this.statistics = stats;
            this.rlEncoding = rlEncoding;
            this.dlEncoding = dlEncoding;
            this.valuesEncoding = valuesEncoding;
        }

        /**
         * @return the bytes for the page
         */
        public BytesInput getBytes()
        {
            return bytes;
        }

        /**
         *
         * @return the statistics for this page (max, min, num_nulls)
         */
        public Statistics getStatistics()
        {
            return statistics;
        }

        /**
         * @return the definition level encoding for this page
         */
        public Encoding getDlEncoding()
        {
            return dlEncoding;
        }

        /**
         * @return the repetition level encoding for this page
         */
        public Encoding getRlEncoding()
        {
            return rlEncoding;
        }

        /**
         * @return the values encoding for this page
         */
        public Encoding getValueEncoding()
        {
            return valuesEncoding;
        }

        public override string ToString()
        {
            return "Page [bytes.size=" + bytes.size() + ", valueCount=" + getValueCount() + ", uncompressedSize=" + getUncompressedSize() + "]";
        }

        public override T accept<T>(Visitor<T> visitor)
        {
            return visitor.visit(this);
        }
    }
}
