using Hotline.Repository.SqlSugar.System;
using Hotline.Settings;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XF.Domain.Authentications;
using XF.Domain.Dependency;

namespace Hotline.Application.Users;
public class OrgApplication : IOrgApplication, IScopeDependency
{
    private readonly ISystemOrganizeRepository _systemOrganizeRepository;
    private readonly ISessionContext _sessionContext;

    public OrgApplication(ISystemOrganizeRepository systemOrganizeRepository, ISessionContext sessionContext)
    {
        _systemOrganizeRepository = systemOrganizeRepository;
        _sessionContext = sessionContext;
    }

    public async Task<IReadOnlyList<SystemOrganize>> GetOrgJsonItems()
    {
        if (_sessionContext.OrgIsCenter)
        {
            return await _systemOrganizeRepository.GetOrgJson();
        }
        else
        {
            return await _systemOrganizeRepository.GetOrgJsonForUser(_sessionContext.RequiredOrgId);
        }
    }
}
