using Infrastructure.Extensions;
using OpenAuth.App.Interface;
using OpenAuth.Repository;
using OpenAuth.Repository.Core;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OpenAuth.App.Base
{
    public class StringTreeApp<T, TDbContext> : TreeApp<T, TDbContext, string>
        where T : TreeEntity<string>, new()
        where TDbContext : SugarUnitOfWork, new()
    {
        public StringTreeApp(ISugarUnitOfWork<TDbContext> unitWork, ISimpleClient<T> repository, IAuth auth)
            : base(unitWork, repository, auth)
        {
        }

        protected override string GetDefaultId()
        {
            return "0";
            /* return ""; */// Define your default Id value for string type
        }

        protected override string GetDefaultCascadeId()
        {
            var max = base.Repository.AsSugarClient().Queryable<T>().Where(a => a.ParentId == "0").Max(a => SqlFunc.ToInt32(a.CascadeId));
            return (max+1).ToString(); // Define your default CascadeId value for string type
        }
    }
}
