/*
 * Copyright (C) 2022 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 android.content.ComponentName;

import com.android.ondevicepersonalization.internal.util.AnnotationValidations;
import com.android.ondevicepersonalization.internal.util.DataClass;
import com.android.ondevicepersonalization.services.data.DbUtils;

/**
 * Query object for the Query table
 */
@DataClass(genBuilder = true)
public class Query {
    /** The id of the query. */
    private long mQueryId = 0;

    /** Time of the query in milliseconds. */
    private final long mTimeMillis;

    /** Package name of the app the made the request */
    @NonNull
    private final String mAppPackageName;

    /** Name of the service that handled the request */
    @NonNull
    private final ComponentName mService;

    /** CertDigest of the service that handled the request */
    @NonNull
    private final String mServiceCertDigest;

    /** Blob representing the query. */
    @NonNull
    private final byte[] mQueryData;

    /** The name of the service */
    public String getServiceName() {
        return DbUtils.toTableValue(mService);
    }



    // 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/Query.java
    //
    // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
    //   Settings > Editor > Code Style > Formatter Control
    //@formatter:off


    @DataClass.Generated.Member
    /* package-private */ Query(
            long queryId,
            long timeMillis,
            @NonNull String appPackageName,
            @NonNull ComponentName service,
            @NonNull String serviceCertDigest,
            @NonNull byte[] queryData) {
        this.mQueryId = queryId;
        this.mTimeMillis = timeMillis;
        this.mAppPackageName = appPackageName;
        AnnotationValidations.validate(
                NonNull.class, null, mAppPackageName);
        this.mService = service;
        AnnotationValidations.validate(
                NonNull.class, null, mService);
        this.mServiceCertDigest = serviceCertDigest;
        AnnotationValidations.validate(
                NonNull.class, null, mServiceCertDigest);
        this.mQueryData = queryData;
        AnnotationValidations.validate(
                NonNull.class, null, mQueryData);

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

    /**
     * The id of the query.
     */
    @DataClass.Generated.Member
    public long getQueryId() {
        return mQueryId;
    }

    /**
     * Time of the query in milliseconds.
     */
    @DataClass.Generated.Member
    public long getTimeMillis() {
        return mTimeMillis;
    }

    /**
     * Package name of the app the made the request
     */
    @DataClass.Generated.Member
    public @NonNull String getAppPackageName() {
        return mAppPackageName;
    }

    /**
     * Name of the service that handled the request
     */
    @DataClass.Generated.Member
    public @NonNull ComponentName getService() {
        return mService;
    }

    /**
     * CertDigest of the service that handled the request
     */
    @DataClass.Generated.Member
    public @NonNull String getServiceCertDigest() {
        return mServiceCertDigest;
    }

    /**
     * Blob representing the query.
     */
    @DataClass.Generated.Member
    public @NonNull byte[] getQueryData() {
        return mQueryData;
    }

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

        private long mQueryId;
        private long mTimeMillis;
        private @NonNull String mAppPackageName;
        private @NonNull ComponentName mService;
        private @NonNull String mServiceCertDigest;
        private @NonNull byte[] mQueryData;

        private long mBuilderFieldsSet = 0L;

        /**
         * Creates a new Builder.
         *
         * @param timeMillis
         *   Time of the query in milliseconds.
         * @param appPackageName
         *   Package name of the app the made the request
         * @param service
         *   Name of the service that handled the request
         * @param serviceCertDigest
         *   CertDigest of the service that handled the request
         * @param queryData
         *   Blob representing the query.
         */
        public Builder(
                long timeMillis,
                @NonNull String appPackageName,
                @NonNull ComponentName service,
                @NonNull String serviceCertDigest,
                @NonNull byte[] queryData) {
            mTimeMillis = timeMillis;
            mAppPackageName = appPackageName;
            AnnotationValidations.validate(
                    NonNull.class, null, mAppPackageName);
            mService = service;
            AnnotationValidations.validate(
                    NonNull.class, null, mService);
            mServiceCertDigest = serviceCertDigest;
            AnnotationValidations.validate(
                    NonNull.class, null, mServiceCertDigest);
            mQueryData = queryData;
            AnnotationValidations.validate(
                    NonNull.class, null, mQueryData);
        }

        /**
         * The id of the query.
         */
        @DataClass.Generated.Member
        public @NonNull Builder setQueryId(long value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x1;
            mQueryId = value;
            return this;
        }

        /**
         * Time of the query in milliseconds.
         */
        @DataClass.Generated.Member
        public @NonNull Builder setTimeMillis(long value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x2;
            mTimeMillis = value;
            return this;
        }

        /**
         * Package name of the app the made the request
         */
        @DataClass.Generated.Member
        public @NonNull Builder setAppPackageName(@NonNull String value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x4;
            mAppPackageName = value;
            return this;
        }

        /**
         * Name of the service that handled the request
         */
        @DataClass.Generated.Member
        public @NonNull Builder setService(@NonNull ComponentName value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x8;
            mService = value;
            return this;
        }

        /**
         * CertDigest of the service that handled the request
         */
        @DataClass.Generated.Member
        public @NonNull Builder setServiceCertDigest(@NonNull String value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x10;
            mServiceCertDigest = value;
            return this;
        }

        /**
         * Blob representing the query.
         */
        @DataClass.Generated.Member
        public @NonNull Builder setQueryData(@NonNull byte... value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x20;
            mQueryData = value;
            return this;
        }

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

            if ((mBuilderFieldsSet & 0x1) == 0) {
                mQueryId = 0;
            }
            Query o = new Query(
                    mQueryId,
                    mTimeMillis,
                    mAppPackageName,
                    mService,
                    mServiceCertDigest,
                    mQueryData);
            return o;
        }

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

    @DataClass.Generated(
            time = 1712096323408L,
            codegenVersion = "1.0.23",
            sourceFile = "packages/modules/OnDevicePersonalization/src/com/android/ondevicepersonalization/services/data/events/Query.java",
            inputSignatures = "private  long mQueryId\nprivate final  long mTimeMillis\nprivate final @android.annotation.NonNull java.lang.String mAppPackageName\nprivate final @android.annotation.NonNull android.content.ComponentName mService\nprivate final @android.annotation.NonNull java.lang.String mServiceCertDigest\nprivate final @android.annotation.NonNull byte[] mQueryData\npublic  java.lang.String getServiceName()\nclass Query extends java.lang.Object implements []\n@com.android.ondevicepersonalization.internal.util.DataClass(genBuilder=true)")
    @Deprecated
    private void __metadata() {}


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

}
