package com.kryptnostic.storage.v2.models;

import java.util.UUID;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Optional;
import com.kryptnostic.v2.constants.Names;
import com.kryptnostic.v2.storage.types.TypeUUIDs;

public class CreateObjectRequest {
    private static final boolean               INHERITING_OWNERSHIP_DEFAULT      = true;
    private static final boolean               INHERITING_CRYPTO_SERVICE_DEFAULT = true;
    private static final boolean               LOCKED_OBJECT_DEFAULT             = true;

    private final UUID                         type;
    private final Optional<VersionedObjectKey> objectId;
    private final Optional<VersionedObjectKey> parentObjectId;
    private final boolean                      inheritingOwnership;
    private final boolean                      inheritingCryptoService;
    private final boolean                      locked;

    public CreateObjectRequest() {
        this(
                TypeUUIDs.DEFAULT_TYPE,
                Optional.<VersionedObjectKey> absent(),
                Optional.<VersionedObjectKey> absent(),
                Optional.<Boolean> absent(),
                Optional.<Boolean> absent(),
                Optional.<Boolean> absent() );
    }

    @JsonCreator
    public CreateObjectRequest(
            @JsonProperty( Names.TYPE_FIELD ) UUID type,
            @JsonProperty( Names.PARENT_OBJECT_ID_FIELD ) Optional<VersionedObjectKey> parentObjectId,
            @JsonProperty( Names.ID_FIELD ) Optional<VersionedObjectKey> objectId,
            @JsonProperty( Names.INHERITING_OWNERSHIP_FIELD ) Optional<Boolean> inheritOwnership,
            @JsonProperty( Names.INHERITING_CRYPTO_SERVICE_FIELD ) Optional<Boolean> inheritCryptoService,
            @JsonProperty( Names.LOCKED_FIELD ) Optional<Boolean> locked ) {
        this.type = type;
        this.parentObjectId = parentObjectId;
        this.objectId = objectId;
        this.inheritingOwnership = inheritOwnership.or( INHERITING_OWNERSHIP_DEFAULT );
        this.inheritingCryptoService = inheritCryptoService.or( INHERITING_CRYPTO_SERVICE_DEFAULT );
        this.locked = locked.or( LOCKED_OBJECT_DEFAULT );
    }

    @JsonProperty( Names.TYPE_FIELD )
    public UUID getType() {
        return type;
    }

    @JsonProperty( Names.ID_FIELD )
    public Optional<VersionedObjectKey> getObjectId() {
        return objectId;
    }

    @JsonProperty( Names.PARENT_OBJECT_ID_FIELD )
    public Optional<VersionedObjectKey> getParentId() {
        return parentObjectId;
    }

    @JsonProperty( Names.INHERITING_OWNERSHIP_FIELD )
    public boolean isInheritingOwnership() {
        return inheritingOwnership;
    }

    @JsonProperty( Names.INHERITING_CRYPTO_SERVICE_FIELD )
    public boolean isInheritingCryptoService() {
        return inheritingCryptoService;
    }

    @JsonProperty( Names.LOCKED_FIELD )
    public boolean isLocked() {
        return locked;
    }
}

@@ -1893,13 +1893,12 @@
 cked
- 
 ) %7B%0A
+
     
@@ -3007,16 +3007,2013 @@
 locked;%0A
-
     %7D%0A
+%0A    public static class Builder %7B%0A        private UUID                         type                 = TypeUUIDs.DEFAULT_TYPE;%0A        private Optional%3CVersionedObjectKey%3E parentObjectkey      = Optional.%3CVersionedObjectKey%3E absent();%0A        private Optional%3CVersionedObjectKey%3E objectId             = Optional.%3CVersionedObjectKey%3E absent();%0A        private Optional%3CBoolean%3E            inheritOwnership     = Optional.%3CBoolean%3E absent();%0A        private Optional%3CBoolean%3E            inheritCryptoService = Optional.%3CBoolean%3E absent();%0A        private Optional%3CBoolean%3E            locked               = Optional.%3CBoolean%3E absent();%0A%0A        public Builder setType( UUID type ) %7B%0A            this.type = type;%0A            return this;%0A        %7D%0A%0A        public Builder setParentObjectId( VersionedObjectKey parentObjectId ) %7B%0A            this.parentObjectkey = Optional.%3CVersionedObjectKey%3E of( parentObjectId );%0A            return this;%0A        %7D%0A%0A        public Builder setObjectId( VersionedObjectKey objectId ) %7B%0A            this.objectId = Optional.%3CVersionedObjectKey%3E of( objectId );%0A            return this;%0A        %7D%0A%0A        public Builder setInheritOwnership( Boolean inheritOwnership ) %7B%0A            this.inheritOwnership = Optional.%3CBoolean%3E of( inheritOwnership );%0A            return this;%0A        %7D%0A%0A        public Builder setInheritCryptoService( Boolean inheritCryptoService ) %7B%0A            this.inheritCryptoService = Optional.%3CBoolean%3E of( inheritCryptoService );%0A            return this;%0A        %7D%0A%0A        public Builder setLocked( Boolean locked ) %7B%0A            this.locked = Optional.%3CBoolean%3E of( locked );%0A            return this;%0A        %7D%0A%0A        public CreateObjectRequest createCreateObjectRequest() %7B%0A            return new CreateObjectRequest(%0A                    type,%0A                    parentObjectkey,%0A                    objectId,%0A                    inheritOwnership,%0A                    inheritCryptoService,%0A                    locked );%0A        %7D%0A    %7D%0A%0A
 %7D%0A

add a builder to CreateObjectRequest