/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed 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.
 */

package com.android.ondevicepersonalization.services.data.events;

import android.annotation.NonNull;

import com.android.ondevicepersonalization.internal.util.AnnotationValidations;
import com.android.ondevicepersonalization.internal.util.DataClass;

/**
 * ColumnSchema object representing a SQL column
 */
@DataClass(
        genBuilder = true,
        genEqualsHashCode = true
)
public class ColumnSchema {
    public static final int SQL_DATA_TYPE_INTEGER = 1;
    public static final int SQL_DATA_TYPE_REAL = 2;
    public static final int SQL_DATA_TYPE_TEXT = 3;
    public static final int SQL_DATA_TYPE_BLOB = 4;

    /** The name of the column. */
    @NonNull
    private final String mName;

    /** The SQL type of the column. */
    @SqlDataType
    private final int mType;

    @Override
    public String toString() {
        String result = mName + " ";
        switch (mType) {
            case ColumnSchema.SQL_DATA_TYPE_INTEGER:
                result += "INTEGER";
                break;
            case ColumnSchema.SQL_DATA_TYPE_REAL:
                result += "REAL";
                break;
            case ColumnSchema.SQL_DATA_TYPE_TEXT:
                result += "TEXT";
                break;
            case ColumnSchema.SQL_DATA_TYPE_BLOB:
            default:
                result += "BLOB";
                break;
        }
        return result;
    }



    // Code below generated by codegen v1.0.23.
    //
    // DO NOT MODIFY!
    // CHECKSTYLE:OFF Generated code
    //
    // To regenerate run:
    // $ codegen $ANDROID_BUILD_TOP/packages/modules/OnDevicePersonalization/src/com/android/ondevicepersonalization/services/data/events/ColumnSchema.java
    //
    // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
    //   Settings > Editor > Code Style > Formatter Control
    //@formatter:off


    @android.annotation.IntDef(prefix = "SQL_DATA_TYPE_", value = {
        SQL_DATA_TYPE_INTEGER,
        SQL_DATA_TYPE_REAL,
        SQL_DATA_TYPE_TEXT,
        SQL_DATA_TYPE_BLOB
    })
    @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE)
    @DataClass.Generated.Member
    public @interface SqlDataType {}

    @DataClass.Generated.Member
    public static String sqlDataTypeToString(@SqlDataType int value) {
        switch (value) {
            case SQL_DATA_TYPE_INTEGER:
                    return "SQL_DATA_TYPE_INTEGER";
            case SQL_DATA_TYPE_REAL:
                    return "SQL_DATA_TYPE_REAL";
            case SQL_DATA_TYPE_TEXT:
                    return "SQL_DATA_TYPE_TEXT";
            case SQL_DATA_TYPE_BLOB:
                    return "SQL_DATA_TYPE_BLOB";
            default: return Integer.toHexString(value);
        }
    }

    @DataClass.Generated.Member
    /* package-private */ ColumnSchema(
            @NonNull String name,
            @SqlDataType int type) {
        this.mName = name;
        AnnotationValidations.validate(
                NonNull.class, null, mName);
        this.mType = type;

        if (!(mType == SQL_DATA_TYPE_INTEGER)
                && !(mType == SQL_DATA_TYPE_REAL)
                && !(mType == SQL_DATA_TYPE_TEXT)
                && !(mType == SQL_DATA_TYPE_BLOB)) {
            throw new java.lang.IllegalArgumentException(
                    "type was " + mType + " but must be one of: "
                            + "SQL_DATA_TYPE_INTEGER(" + SQL_DATA_TYPE_INTEGER + "), "
                            + "SQL_DATA_TYPE_REAL(" + SQL_DATA_TYPE_REAL + "), "
                            + "SQL_DATA_TYPE_TEXT(" + SQL_DATA_TYPE_TEXT + "), "
                            + "SQL_DATA_TYPE_BLOB(" + SQL_DATA_TYPE_BLOB + ")");
        }


        // onConstructed(); // You can define this method to get a callback
    }

    /**
     * The name of the column.
     */
    @DataClass.Generated.Member
    public @NonNull String getName() {
        return mName;
    }

    /**
     * The SQL type of the column.
     */
    @DataClass.Generated.Member
    public @SqlDataType int getType() {
        return mType;
    }

    @Override
    @DataClass.Generated.Member
    public boolean equals(@android.annotation.Nullable Object o) {
        // You can override field equality logic by defining either of the methods like:
        // boolean fieldNameEquals(ColumnSchema other) { ... }
        // boolean fieldNameEquals(FieldType otherValue) { ... }

        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        @SuppressWarnings("unchecked")
        ColumnSchema that = (ColumnSchema) o;
        //noinspection PointlessBooleanExpression
        return true
                && java.util.Objects.equals(mName, that.mName)
                && mType == that.mType;
    }

    @Override
    @DataClass.Generated.Member
    public int hashCode() {
        // You can override field hashCode logic by defining methods like:
        // int fieldNameHashCode() { ... }

        int _hash = 1;
        _hash = 31 * _hash + java.util.Objects.hashCode(mName);
        _hash = 31 * _hash + mType;
        return _hash;
    }

    /**
     * A builder for {@link ColumnSchema}
     */
    @SuppressWarnings("WeakerAccess")
    @DataClass.Generated.Member
    public static class Builder {

        private @NonNull String mName;
        private @SqlDataType int mType;

        private long mBuilderFieldsSet = 0L;

        public Builder() {
        }

        /**
         * Creates a new Builder.
         *
         * @param name
         *   The name of the column.
         * @param type
         *   The SQL type of the column.
         */
        public Builder(
                @NonNull String name,
                @SqlDataType int type) {
            mName = name;
            AnnotationValidations.validate(
                    NonNull.class, null, mName);
            mType = type;

            if (!(mType == SQL_DATA_TYPE_INTEGER)
                    && !(mType == SQL_DATA_TYPE_REAL)
                    && !(mType == SQL_DATA_TYPE_TEXT)
                    && !(mType == SQL_DATA_TYPE_BLOB)) {
                throw new java.lang.IllegalArgumentException(
                        "type was " + mType + " but must be one of: "
                                + "SQL_DATA_TYPE_INTEGER(" + SQL_DATA_TYPE_INTEGER + "), "
                                + "SQL_DATA_TYPE_REAL(" + SQL_DATA_TYPE_REAL + "), "
                                + "SQL_DATA_TYPE_TEXT(" + SQL_DATA_TYPE_TEXT + "), "
                                + "SQL_DATA_TYPE_BLOB(" + SQL_DATA_TYPE_BLOB + ")");
            }

        }

        /**
         * The name of the column.
         */
        @DataClass.Generated.Member
        public @NonNull Builder setName(@NonNull String value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x1;
            mName = value;
            return this;
        }

        /**
         * The SQL type of the column.
         */
        @DataClass.Generated.Member
        public @NonNull Builder setType(@SqlDataType int value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x2;
            mType = value;
            return this;
        }

        /** Builds the instance. This builder should not be touched after calling this! */
        public @NonNull ColumnSchema build() {
            checkNotUsed();
            mBuilderFieldsSet |= 0x4; // Mark builder used

            ColumnSchema o = new ColumnSchema(
                    mName,
                    mType);
            return o;
        }

        private void checkNotUsed() {
            if ((mBuilderFieldsSet & 0x4) != 0) {
                throw new IllegalStateException(
                        "This Builder should not be reused. Use a new Builder instance instead");
            }
        }
    }

    @DataClass.Generated(
            time = 1693945130500L,
            codegenVersion = "1.0.23",
            sourceFile = "packages/modules/OnDevicePersonalization/src/com/android/ondevicepersonalization/services/data/events/ColumnSchema.java",
            inputSignatures = "public static final  int SQL_DATA_TYPE_INTEGER\npublic static final  int SQL_DATA_TYPE_REAL\npublic static final  int SQL_DATA_TYPE_TEXT\npublic static final  int SQL_DATA_TYPE_BLOB\nprivate final @android.annotation.NonNull java.lang.String mName\nprivate final @com.android.ondevicepersonalization.services.data.events.ColumnSchema.SqlDataType int mType\nclass ColumnSchema extends java.lang.Object implements []\n@com.android.ondevicepersonalization.internal.util.DataClass(genBuilder=true, genEqualsHashCode=true)")
    @Deprecated
    private void __metadata() {}


    //@formatter:on
    // End of generated code

}
