package com.jscape.inet.sftp.protocol.v3.messages;

/**
 * @author Alex Usun
 */
public class FileAttributeFlags {

    public final boolean sizeAttributePresent;
    public final boolean userIdGroupIdAttributesPresent;
    public final boolean permissionsAttributePresent;
    public final boolean accessModificationTimeAttributesPresent;
    public final boolean extendedAttributesPresent;

    public static FileAttributeFlags flagsFor(FileAttributes attributes) {
        return new FileAttributeFlags(attributes.size != null,
                                       attributes.userId != null || attributes.groupId != null,
                                       attributes.permissions != null,
                                       attributes.accessTime != null || attributes.modificationTime != null,
                                      !attributes.extendedData.isEmpty());
    }

    public FileAttributeFlags(boolean sizeAttributePresent,
                              boolean userIdGroupIdAttributesPresent,
                              boolean permissionsAttributePresent,
                              boolean accessModificationTimeAttributesPresent,
                              boolean extendedAttributesPresent) {
        this.sizeAttributePresent = sizeAttributePresent;
        this.userIdGroupIdAttributesPresent = userIdGroupIdAttributesPresent;
        this.permissionsAttributePresent = permissionsAttributePresent;
        this.accessModificationTimeAttributesPresent = accessModificationTimeAttributesPresent;
        this.extendedAttributesPresent = extendedAttributesPresent;
    }

    @Override
    public String toString() {
        return "FileAttributesFlags {"
               + "sizeAttributePresent=" + this.sizeAttributePresent
               + ", userIdGroupIdAttributesPresent=" + this.userIdGroupIdAttributesPresent
               + ", permissionsAttributePresent=" + this.permissionsAttributePresent
               + ", accessModificationTimeAttributesPresent=" + this.accessModificationTimeAttributesPresent
               + ", extendedAttributesPresent=" + this.extendedAttributesPresent
               + '}';
    }
}
