namespace adas_core.Domain.Models.AppSettings;

/// <summary>
/// Represents the configuration settings related to permissions.
/// </summary>
public class PermissionSettings
{
    public SourcePermissions Admin { get; set; } = new(
        new DisplayPermissionTypes(
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            true
        ),
        new DisplayPermissionTypes(
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            true
        ),
        new PanelPermissionTypes(
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            true
        )
    );

    public SourcePermissions Developer { get; set; } = new(
        new DisplayPermissionTypes(
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            true
        ),
        new DisplayPermissionTypes(
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            true
        ),
        new PanelPermissionTypes(
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            new UserActions(true, true, true, true, true),
            true
        )
    );

    public SourcePermissions DoctorChief { get; set; } = new(
        new DisplayPermissionTypes(
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, false, false, true, false),
            false
        ),
        new DisplayPermissionTypes(
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            false
        ),
        new PanelPermissionTypes(
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            false
        )
    );

    public SourcePermissions Doctor { get; set; } = new(
        new DisplayPermissionTypes(
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            false
        ),
        new DisplayPermissionTypes(
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            false
        ),
        new PanelPermissionTypes(
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            false
        )
    );

    public SourcePermissions NursingSupervisor { get; set; } = new(
        new DisplayPermissionTypes(
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, false, false, true, false),
            false
        ),
        new DisplayPermissionTypes(
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            false
        ),
        new PanelPermissionTypes(
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            new UserActions(false, true, false, true, false),
            false
        )
    );

    public SourcePermissions Nurse { get; set; } = new(
        new DisplayPermissionTypes(
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            false
        ),
        new DisplayPermissionTypes(
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            false
        ),
        new PanelPermissionTypes(
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            false
        )
    );

    public SourcePermissions Guest { get; set; } = new(
        new DisplayPermissionTypes(
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            false
        ),
        new DisplayPermissionTypes(
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            new UserActions(false, false, false, true, false),
            false
        ),
        new PanelPermissionTypes(
            new UserActions(false, false, false, true, true),
            new UserActions(false, false, false, true, true),
            new UserActions(false, false, false, true, true),
            new UserActions(false, false, false, true, true),
            new UserActions(false, false, false, true, true),
            new UserActions(false, false, false, true, true),
            new UserActions(false, false, false, true, true),
            new UserActions(false, false, false, true, true),
            new UserActions(false, false, false, true, true),
            new UserActions(false, false, false, true, true),
            new UserActions(false, false, false, true, true),
            new UserActions(false, false, false, true, true),
            false
        )
    );
}

public class SourcePermissions(
    DisplayPermissionTypes unit,
    DisplayPermissionTypes display,
    PanelPermissionTypes panel)
{
    public DisplayPermissionTypes Unit { get; set; } = unit;
    public DisplayPermissionTypes Display { get; set; } = display;
    public PanelPermissionTypes Panel { get; set; } = panel;
}

public class DisplayPermissionTypes(
    UserActions admissions,
    UserActions discharges,
    UserActions obs,
    UserActions demographicData,
    UserActions boxBlocking,
    UserActions notices,
    UserActions cell,
    bool useDemoMode)
{
    public UserActions Admissions { get; set; } = admissions;
    public UserActions Discharges { get; set; } = discharges;
    public UserActions Obs { get; set; } = obs;
    public UserActions Cell { get; set; } = cell;
    public UserActions DemographicData { get; set; } = demographicData;
    public UserActions BoxBlocking { get; set; } = boxBlocking;
    public UserActions Notices { get; set; } = notices;
    public bool UseDemoMode { get; set; } = useDemoMode;
}

public class PanelPermissionTypes(
    UserActions units,
    UserActions displays,
    UserActions displayConfigs,
    UserActions masterLists,
    UserActions treatments,
    UserActions patients,
    UserActions medicines,
    UserActions pumps,
    UserActions users,
    UserActions configObservations,
    UserActions observations,
    UserActions audits,
    bool useDemoMode)
{
    public UserActions Units { get; set; } = units;
    public UserActions Displays { get; set; } = displays;
    public UserActions DisplayConfigs { get; set; } = displayConfigs;
    public UserActions MasterLists { get; set; } = masterLists;
    public UserActions Treatments { get; set; } = treatments;
    public UserActions Patients { get; set; } = patients;
    public UserActions Medicines { get; set; } = medicines;
    public UserActions Pumps { get; set; } = pumps;
    public UserActions Users { get; set; } = users;
    public UserActions ConfigObservations { get; set; } = configObservations;
    public UserActions Observations { get; set; } = observations;
    public UserActions Audits { get; set; } = audits;
    public bool UseDemoMode { get; set; } = useDemoMode;
}

/// <summary>
/// Represents a set of user permissions indicating whether the user is allowed to create, update, delete, read, or execute specific operations.
/// </summary>
/// <remarks>
/// This type captures granular action-level authorization flags, allowing the application to enforce and check individual user capabilities across supported operations.
/// </remarks>
public class UserActions(bool create, bool update, bool delete, bool read, bool execute)
{
    public bool Create { get; set; } = create;
    public bool Update { get; set; } = update;
    public bool Delete { get; set; } = delete;
    public bool Read { get; set; } = read;
    public bool Execute { get; set; } = execute;
}