using e_suite.Database.Audit.Attributes;
using e_suite.Database.Core.Models;
using e_suite.Database.Core.Tables.Domain;
using e_suite.Database.Core.Tables.UserManager;
using eSuite.Core.Enums;
using eSuite.Core.Workflow;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace e_suite.Database.Core.Tables.Activity;

[DisplayName("Activity Assignment")]
[Table("ActivityAssignments", Schema = "Activity")]
[Index(nameof(Guid), IsUnique = true)]
public class ActivityAssignment : IGeneralId, ISoftDeletable, IRuntimeOutcomes
{
    [Key]
    public long Id { get; set; }

    public Guid Guid { get; set; }

    [AuditSoftDelete(true)]
    [Required]
    [DefaultValue(false)]
    public bool Deleted { get; set; }

    public long TaskId { get; set; }
    

    public Raci Raci { get; set; }

    public long? RoleId { get; set; }

    public long? UserId { get; set; }

    public bool AllowNoVerdict { get; set; } = false;

    public bool Bypassable { get; set; } = false;
    
    [AuditLastUpdated]
    public DateTimeOffset LastUpdated { get; set; }

    [AuditParent]
    [ForeignKey(nameof(TaskId))]
    public virtual ActivityTask Task { get; set; } = null!;

    [ForeignKey(nameof(RoleId))]
    public virtual Role Role { get; set; } = null!;

    [ForeignKey(nameof(UserId))]
    public virtual User User { get; set; } = null!;

    public List<string> Outcomes { get; set; } = [];
    public DateTimeOffset? StartDateTime { get; set; }
    public DateTimeOffset? FinishDateTime { get; set; }
    public string Comments { get; set; } = string.Empty;
    public long? CompletedByUserId { get; set; }
    public string? CompletedByUserDisplayName { get; set; }
    public ActivityState ActivityState { get; set; } = ActivityState.Pending;
}