/*
 * Automatically generated by jrpcgen 1.0.7 on 29.11.2012
 * jrpcgen is part of the "Remote Tea.Net" ONC/RPC package for C#
 * See http://remotetea.sourceforge.net for details
 */
using org.acplt.oncrpc;

namespace NFSLibrary.Protocols.Commons
{
    public class NFSPermission
    {
        private byte _user;
        private byte _group;
        private byte _other;

        public NFSPermission()
        { }

        public NFSPermission(byte UserAccess, byte GroupAccess, byte OtherAccess)
        {
            this._user = UserAccess;
            this._group = GroupAccess;
            this._other = OtherAccess;
        }

        public byte UserAccess
        {
            get
            { return this._user; }
            set
            { this._user = value; }
        }

        public byte GroupAccess
        {
            get
            { return this._group; }
            set
            { this._group = value; }
        }

        public byte OtherAccess
        {
            get
            { return this._other; }
            set
            { this._other = value; }
        }

        public int Mode
        {
            get
            {
                if (_user == 0xff && _group == 0xff && _other == 0xff)
                    return -1;
                /* Calculate Permission */
                return
                    (((int)this._user) << 6) | (((int)this._group) << 3) | ((int)this._other);
                /*  ---  */
            }
            set
            {
                int tUser = value, tGroup = value, tOther = value;

                this._user = (byte)((tUser >> 6) & 0x7);
                this._group = (byte)((tGroup >> 3) & 0x7);
                this._other = (byte)(tOther & 0x7);
            }
        }

        override
        public string ToString()
        {
            return calc_mode(_user)+" | "+calc_mode(_group)+" | "+calc_mode(_other);
        }

        private string calc_mode(byte modfg)
        {
            switch (modfg)
            {
                case 1:
                    return "x";
                case 2:
                    return "w";
                case 3:
                    return "wx";
                case 4:
                    return "r";
                case 5:
                    return "rx";
                case 6:
                    return "rw";
                case 7:
                    return "rwx";
                default:
                    return "";
            }
        }
    }
}