using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using AyCode.Interfaces.Entities;
using AyCode.Interfaces.TimeStampInfo;
using AyCode.Models.Enums;

namespace TIAM.Entities.Permissions;

[Table("PermissionContextMapping")]
public class PermissionContextMapping : IEntityGuid, ITimeStampInfo
{
    [Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
    public Guid Id { get; set; } 
    
    public Guid ContextId { get; set; } //product or serviceprovider
    public Guid SubjectId  { get; set; } //group or user

    public PermissionContextMappingSubjectType SubjectType { get; set; } //1 for user, 2 for group
    public int Permissions { get; set; }
    public bool IsBuiltin { get; set; }

    public DateTime Created { get; set; }
    public DateTime Modified { get; set; }

    public PermissionContextMapping(Guid contextId, Guid subjectId, PermissionContextMappingSubjectType subjectType, int permissions, bool isBuiltin) : this(Guid.NewGuid(), contextId, subjectId, subjectType, permissions, isBuiltin) { }
    public PermissionContextMapping(Guid id, Guid contextId, Guid subjectId, PermissionContextMappingSubjectType subjectType, int permissions, bool isBuiltin)
    {
        Id = id;
        ContextId = contextId;
        SubjectId = subjectId;
        SubjectType = subjectType;
        Permissions = permissions;
        IsBuiltin = isBuiltin;
    }
}