using Edu.Model.ViewModel.StudyAbroad;
using Edu.Repository.StudyAbroad;
using System.Collections.Generic;
using VT.FW.DB;

namespace Edu.Module.StudyAbroad
{
    /// <summary>
    /// 供应商处理类
    /// </summary>
    public class SupplierModule
    {
        /// <summary>
        /// 供应商仓储层对象
        /// </summary>
        private readonly RB_SupplierRepository supplierRepository = new RB_SupplierRepository();

        /// <summary>
        /// 获取供应商分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Supplier_ViewModel> GetSupplierPageModule(int pageIndex, int pageSize, out long rowsCount, RB_Supplier_ViewModel query)
        {
            return supplierRepository.GetSupplierPageRepository(pageIndex, pageSize, out rowsCount, query);
        }

        /// <summary>
        /// 获取供应商列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Supplier_ViewModel> GetSupplierListModule(RB_Supplier_ViewModel query)
        {
            return supplierRepository.GetSupplierListRepository(query);
        }

        /// <summary>
        /// 新增修改供应商
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool SetSupplierModule(RB_Supplier_ViewModel model)
        {
            bool flag = false;
            if (model.Id > 0)
            {
                Dictionary<string, object> fileds = new Dictionary<string, object>()
                {
                    { nameof(RB_Supplier_ViewModel.Type),model.Type},
                    { nameof(RB_Supplier_ViewModel.Name),model.Name.Trim()},
                    { nameof(RB_Supplier_ViewModel.LinkMan),model.LinkMan},
                    { nameof(RB_Supplier_ViewModel.LinkTel),model.LinkTel},
                    { nameof(RB_Supplier_ViewModel.LinkAddress),model.LinkAddress},
                    { nameof(RB_Supplier_ViewModel.Remark),model.Remark},
                    { nameof(RB_Supplier_ViewModel.CommissionType),model.CommissionType},
                    { nameof(RB_Supplier_ViewModel.CommissionMoney),model.CommissionMoney},
                    { nameof(RB_Supplier_ViewModel.ContractUrl),model.ContractUrl},
                };
                flag = supplierRepository.Update(fileds, new WhereHelper(nameof(RB_Supplier_ViewModel.Id), model.Id));
            }
            else
            {
                var newId = supplierRepository.Insert(model);
                model.Id = newId;
                flag = newId > 0;
            }
            return flag;
        }

        /// <summary>
        /// 获取供应商信息
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public RB_Supplier_ViewModel GetSupplierModule(object Id)
        {
            return supplierRepository.GetEntity<RB_Supplier_ViewModel>(Id);
        }

        /// <summary>
        /// 更新供应商状态
        /// </summary>
        /// <param name="Id">供应商编号</param>
        /// <param name="Status">状态(0-正常，1-删除)</param>
        /// <returns></returns>
        public bool RemoveSupplierModule(int Id, int Status)
        {
            Dictionary<string, object> fileds = new Dictionary<string, object>()
            {
                { nameof(RB_Supplier_ViewModel.Status),Status},
            };
            bool flag = supplierRepository.Update(fileds, new WhereHelper(nameof(RB_Supplier_ViewModel.Id), Id));
            return flag;
        }
    }
}
