
using BPA.KitChen.GroupMeal.Core.Entity;
using BPA.KitChen.GroupMeal.Core.Enum;
using BPA.KitChen.GroupMeal.SqlSugar;
using MySqlConnector;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace BPA.KitChen.GroupMeal.Application.BaseDto
{
    /// <summary>
    /// Dto参数验证
    /// </summary>
   public class DtoValidator
    {

        /// <summary>
        /// 验证会员
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static ValidationResult Member(string id)
        {
            var data = SqlSugarDb.Db.Queryable<BPA_MemberInfo>().First(x => x.Id == id&&x.IsDeleted==0);
            return data == null ? new ValidationResult("会员不存在") : ValidationResult.Success;
        }


        /// <summary>
        /// 验证会员标签的合法性
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static ValidationResult MemberTag(string id)
        {
            var data = SqlSugarDb.Db.Queryable<BPA_MemberTag>().First(x=>x.Id==id);
            return data == null ? new ValidationResult("会员标签不存在") : ValidationResult.Success;
        }
        /// <summary>
        /// 验证会员标签的合法性
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static ValidationResult MemberTagList(List<string> ids)
        {
            var data = SqlSugarDb.Db.Queryable<BPA_MemberTag>().Where(x => ids.Contains(x.Id) && x.IsDeleted == 0&&x.Status== CommonStatus.ENABLE).ToList();
            return data.Count<=0 ? new ValidationResult("会员标签不存在") : ValidationResult.Success;
        }

        /// <summary>
        /// 会员平台
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static ValidationResult MemberPlatformType(int type) 
        {
            return !System.Enum.IsDefined(typeof(PlatformType), type) ? new ValidationResult("平台类型不存在") : ValidationResult.Success;

        }

        /// <summary>
        /// 会员平台
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static ValidationResult Status(int type)
        {
            return !System.Enum.IsDefined(typeof(CommonStatus), type) ? new ValidationResult("状态错误") : ValidationResult.Success;

        }
        /// <summary>
        /// 优惠券使用
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static ValidationResult CouponUseType(int type)
        {
            return !System.Enum.IsDefined(typeof(CouponUseType), type) ? new ValidationResult("状态错误") : ValidationResult.Success;

        }
    }
}
