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

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

    public final boolean sizeAttributePresent;
    public final boolean permissionsAttributePresent;
    public final boolean accessTimeAttributePresent;
    public final boolean createTimeAttributePresent;
    public final boolean modifyTimeAttributePresent;
    public final boolean aclAttributePresent;
    public final boolean ownerGroupAttributesPresent;
    public final boolean subsecondTimesPresent;
    public final boolean extendedAttributesPresent;

    public static FileAttributeFlags flagsFor(FileAttributes attributes) {
        return new FileAttributeFlags(attributes.size != null,
                                      attributes.permissions != null,
                                      attributes.accessTime != null,
                                      attributes.createTime != null,
                                      attributes.modificationTime != null,
                                      attributes.acls != null,
                                      attributes.owner != null || attributes.group != null,
                                      false,
                                      !attributes.extendedData.isEmpty());
    }

    public static FileAttributeFlags empty() {
        return new FileAttributeFlags(false, false, false, false, false, false, false, false, false);
    }

    public static FileAttributeFlags size() {
        return new FileAttributeFlags(true, false, false, false, false, false, false, false, false);
    }

    public static FileAttributeFlags permissions() {
        return new FileAttributeFlags(false, true, false, false, false, false, false, false, false);
    }

    public static FileAttributeFlags modificationTime() {
        return new FileAttributeFlags(false, false, false, false, true, false, false, false, false);
    }

    public FileAttributeFlags(boolean sizeAttributePresent,
                              boolean permissionsAttributePresent,
                              boolean accessTimeAttributePresent,
                              boolean createTimeAttributePresent,
                              boolean modifyTimeAttributePresent,
                              boolean aclAttributePresent,
                              boolean ownerGroupAttributesPresent,
                              boolean subsecondTimesPresent,
                              boolean extendedAttributesPresent) {
        this.sizeAttributePresent = sizeAttributePresent;
        this.permissionsAttributePresent = permissionsAttributePresent;
        this.accessTimeAttributePresent = accessTimeAttributePresent;
        this.createTimeAttributePresent = createTimeAttributePresent;
        this.modifyTimeAttributePresent = modifyTimeAttributePresent;
        this.aclAttributePresent = aclAttributePresent;
        this.ownerGroupAttributesPresent = ownerGroupAttributesPresent;
        this.subsecondTimesPresent = subsecondTimesPresent;
        this.extendedAttributesPresent = extendedAttributesPresent;
    }

    @Override
    public String toString() {
        return "FileAttributeFlags {"
               + "sizeAttributePresent=" + this.sizeAttributePresent
               + ", permissionsAttributePresent=" + this.permissionsAttributePresent
               + ", accessTimeAttributePresent=" + this.accessTimeAttributePresent
               + ", createTimeAttributePresent=" + this.createTimeAttributePresent
               + ", modifyTimeAttributePresent=" + this.modifyTimeAttributePresent
               + ", aclAttributePresent=" + this.aclAttributePresent
               + ", ownerGroupAttributesPresent=" + this.ownerGroupAttributesPresent
               + ", subsecondTimesPresent=" + this.subsecondTimesPresent
               + ", extendedAttributesPresent=" + this.extendedAttributesPresent
               + '}';
    }
}
