using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using AyaNova.Models;


namespace AyaNova.Biz
{


    //THIS IS USED BY THE ATTACHMENT CONTROLLER
    //IN THEORY WE ONLY NEED TO CHECK FOR ATTACHABLE TYPES, BUT I CAN SEE IT'S POTENTIAL USEFULNESS DOWN THE ROAD FOR OTHER THINGS
    internal static class BizObjectExistsInDatabase
    {


        //Returns existance status of object type and id specified in database

        internal static async Task<bool> ExistsAsync(AyaType objectType, long id, AyContext ct)
        {
            //new up a context??

            switch (objectType)
            {
                //CoreBizObject add here
                case AyaType.NoType://no type always exists and this is used by orphaned attachments
                    return true;
                case AyaType.FileAttachment:
                    return await ct.FileAttachment.AnyAsync(z => z.Id == id);
                case AyaType.DataListView:
                    return await ct.DataListView.AnyAsync(z => z.Id == id);
                case AyaType.FormCustom:
                    return await ct.FormCustom.AnyAsync(z => z.Id == id);
                case AyaType.User:
                    return await ct.User.AnyAsync(z => z.Id == id);
                case AyaType.Widget:
                    return await ct.Widget.AnyAsync(z => z.Id == id);
                case AyaType.Customer:
                    return await ct.Customer.AnyAsync(z => z.Id == id);
                case AyaType.Contract:
                    return await ct.Contract.AnyAsync(z => z.Id == id);
                case AyaType.HeadOffice:
                    return await ct.HeadOffice.AnyAsync(z => z.Id == id);
                case AyaType.LoanUnit:
                    return await ct.LoanUnit.AnyAsync(z => z.Id == id);
                case AyaType.Part:
                    return await ct.Part.AnyAsync(z => z.Id == id);
                case AyaType.PM:
                    return await ct.PM.AnyAsync(z => z.Id == id);
                case AyaType.PMItem:
                    return await ct.PMItem.AnyAsync(z => z.Id == id);
                case AyaType.PMTemplate:
                    return await ct.PMTemplate.AnyAsync(z => z.Id == id);
                case AyaType.PMTemplateItem:
                    return await ct.PMTemplateItem.AnyAsync(z => z.Id == id);
                case AyaType.Project:
                    return await ct.Project.AnyAsync(z => z.Id == id);
                case AyaType.PurchaseOrder:
                    return await ct.PurchaseOrder.AnyAsync(z => z.Id == id);
                case AyaType.Quote:
                    return await ct.Quote.AnyAsync(z => z.Id == id);
                case AyaType.QuoteItem:
                    return await ct.QuoteItem.AnyAsync(z => z.Id == id);
                case AyaType.QuoteTemplate:
                    return await ct.QuoteTemplate.AnyAsync(z => z.Id == id);
                case AyaType.QuoteTemplateItem:
                    return await ct.QuoteTemplateItem.AnyAsync(z => z.Id == id);
                case AyaType.Unit:
                    return await ct.Unit.AnyAsync(z => z.Id == id);
                case AyaType.UnitModel:
                    return await ct.UnitModel.AnyAsync(z => z.Id == id);
                case AyaType.Vendor:
                    return await ct.Vendor.AnyAsync(z => z.Id == id);
                //--- WorkOrder
                case AyaType.WorkOrder:
                    return await ct.WorkOrder.AnyAsync(z => z.Id == id);
                case AyaType.WorkOrderItem:
                    return await ct.WorkOrderItem.AnyAsync(z => z.Id == id);
                case AyaType.WorkOrderItemExpense:
                    return await ct.WorkOrderItemExpense.AnyAsync(z => z.Id == id);
                case AyaType.WorkOrderItemLabor:
                    return await ct.WorkOrderItemLabor.AnyAsync(z => z.Id == id);
                case AyaType.WorkOrderItemLoan:
                    return await ct.WorkOrderItemLoan.AnyAsync(z => z.Id == id);
                case AyaType.WorkOrderItemPart:
                    return await ct.WorkOrderItemPart.AnyAsync(z => z.Id == id);
                case AyaType.WorkOrderItemPartRequest:
                    return await ct.WorkOrderItemPartRequest.AnyAsync(z => z.Id == id);
                case AyaType.WorkOrderItemScheduledUser:
                    return await ct.WorkOrderItemScheduledUser.AnyAsync(z => z.Id == id);
                case AyaType.WorkOrderItemTask:
                    return await ct.WorkOrderItemTask.AnyAsync(z => z.Id == id);
                case AyaType.WorkOrderItemTravel:
                    return await ct.WorkOrderItemTravel.AnyAsync(z => z.Id == id);
                case AyaType.WorkOrderItemUnit:
                    return await ct.WorkOrderItemUnit.AnyAsync(z => z.Id == id);
                //---
                case AyaType.WorkOrderTemplate:
                    return await ct.WorkOrderTemplate.AnyAsync(z => z.Id == id);
                case AyaType.WorkOrderTemplateItem:
                    return await ct.WorkOrderTemplateItem.AnyAsync(z => z.Id == id);
                case AyaType.Report:
                    return await ct.Report.AnyAsync(z => z.Id == id);
                default:
                    throw new System.NotSupportedException($"AyaNova.Biz.BizObjectExistsInDatabase::ExistsAsync type {objectType.ToString()} is not supported");
            }

        }





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

    }//eoc


}//eons

