using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Mvc;

using EnumsNET;
using AyaNova.Util;
using AyaNova.Api.ControllerHelpers;
using AyaNova.Biz;
using AyaNova.Models;


namespace AyaNova.Biz
{


    internal static class BizObjectFactory
    {


        //Returns the biz object class that corresponds to the type presented
        //Used by SEARCH and objects with JOBS
        internal static BizObject GetBizObject(AyaType ayaType, AyContext dbcontext, long userId = 1, AuthorizationRoles roles = AuthorizationRoles.All)
        {
            switch (ayaType)
            {
                //CoreBizObject add here
                case AyaType.ServerJob:
                    return new JobOperationsBiz(dbcontext, userId, roles);
                case AyaType.TrialSeeder:
                    return new TrialBiz(dbcontext, userId, roles);
                case AyaType.Translation:
                    return new TranslationBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);
                case AyaType.DataListView:
                    return new DataListViewBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);
                case AyaType.FormCustom:
                    return new FormCustomBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);
                case AyaType.Widget:
                    return new WidgetBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);

                case AyaType.Customer:
                    return new CustomerBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);
                case AyaType.User:
                    return new UserBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);


                case AyaType.Contract:
                    return new ContractBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);
                case AyaType.HeadOffice:
                    return new HeadOfficeBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);
                case AyaType.LoanUnit:
                    return new LoanUnitBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);
                case AyaType.Part:
                    return new PartBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);
                case AyaType.PM:
                    return new PMBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);

                case AyaType.PMTemplate:
                    return new PMTemplateBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);

                case AyaType.Project:
                    return new ProjectBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);
                case AyaType.PurchaseOrder:
                    return new PurchaseOrderBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);
                case AyaType.Quote:
                    return new QuoteBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);

                case AyaType.QuoteTemplate:
                    return new QuoteTemplateBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);

                case AyaType.Unit:
                    return new UnitBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);
                case AyaType.UnitModel:
                    return new UnitModelBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);
                case AyaType.Vendor:
                    return new VendorBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);
                //--- WorkOrder
                case AyaType.WorkOrder:
                case AyaType.WorkOrderItem:
                case AyaType.WorkOrderItemExpense:
                case AyaType.WorkOrderItemLabor:
                case AyaType.WorkOrderItemLoan:
                case AyaType.WorkOrderItemPart:
                case AyaType.WorkOrderItemPartRequest:
                case AyaType.WorkOrderItemScheduledUser:
                case AyaType.WorkOrderItemTask:
                case AyaType.WorkOrderItemTravel:
                case AyaType.WorkOrderItemUnit:
                    return new WorkOrderBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);
                //---
                case AyaType.WorkOrderTemplate:
                    return new WorkOrderTemplateBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);

                default:
                    throw new System.NotSupportedException($"AyaNova.BLL.BizObjectFactory::GetBizObject type {ayaType.ToString()} is not supported");
            }

        }


        /////////////////////////////////////////////////////////////////////

    }//eoc


}//eons

