using LinqToDB.Mapping;

namespace MasaBlazorApp3.Pojo
{
    [Table("role")]
    public class Role
    {

        [PrimaryKey, Identity]
        [Column("id")]
        public int Id { get; set; }
        [Column("role_name")]
        public string RoleName { get; set; }
        //[Column("role_des")]
        //public string Description { get; set; }
        [Column("machine_id")]
        public string MachineId { get; set; }

        [Column("permissions")]
        public string permissions { get; set; }

        [Column(IsColumn = false)]
        public List<Premission> permissionList {
            get
            {

                return null;
            }
        }

        [Column(IsColumn = false)]
        public IEnumerable<int> permissionIds
        {
            get
            {
                return !String.IsNullOrEmpty(permissions) ? permissions.Split(",").Select(s => Convert.ToInt32(s)): Enumerable.Empty<int>();
            }
            set
            {
                if (value == null)
                {
                    permissions = "";
                } else
                {
                    permissions = string.Join(",", value);
                }
            }
        }
    }
}
