using System;
using System.Collections.Generic;
using System.Linq;

namespace JiaZhiQuan.Common.Models
{
    /// <summary>
    /// 后台管理商品查询、订单查询接口的商品类型
    /// 这些商品类型统一管理
    /// </summary>
    public class GoodsType
    {
        public int goodType;
        public string typeName;
        public List<VirtualType> virtualTypes;
        public List<StateType> stateTypes;

        private static List<GoodsType> goodsTypes => new List<GoodsType> {
            new GoodsType { goodType=0,typeName="实体商品",stateTypes=stateTypes1},
            new GoodsType { goodType=1,typeName="虚拟商品",virtualTypes=virtualTypes1}
        };

        private static List<VirtualType> virtualTypes1 => new List<VirtualType> {
             new VirtualType{ virtualType=1, typeName="链接",stateTypes=stateTypes1},
             new VirtualType{ virtualType=2, typeName="支付宝红包",stateTypes=stateTypes2} ,
             new VirtualType{ virtualType=3, typeName="卡密",stateTypes=stateTypes1},
             new VirtualType{ virtualType=4, typeName="API直充",stateTypes=stateTypes1}
        };
        private static List<StateType> stateTypes1 => new List<StateType> {
             new StateType{ state=1, typeName="待发货"},
             new StateType{ state=2, typeName="已发货"}
        };
        private static List<StateType> stateTypes2 => new List<StateType> {
             new StateType{ state=10, typeName="待兑换"},
             new StateType{ state=13, typeName="兑换中"},
             new StateType{ state=11, typeName="已兑换"},
             new StateType{ state=12, typeName="已过期"}
        };

        public static List<VirtualType>? ListVirtualTypeByGoodsType(int? goodsType)
        {
            return goodsTypes.FirstOrDefault(t => t.goodType == goodsType)?.virtualTypes;
        }

        public static List<StateType>? ListStateTypeByGoodsType(int? goodsType, int? virtualType = -1)
        {
            if (0 == goodsType)
            {
                return goodsTypes[0].stateTypes;
            }
            else
            {
                return goodsTypes.FirstOrDefault(t => t.goodType == goodsType)?.
                    virtualTypes.FirstOrDefault(v => v.virtualType == virtualType)?.stateTypes;
            }
        }

        public static List<GoodsType> ListGoodsTypes()
        {
            return goodsTypes;
        }

        public static string? TransStateName(int? isVirtual, int? virtualType, int? state)
        {
            List<StateType>? sta = ListStateTypeByGoodsType(isVirtual, virtualType);
            return sta?.FirstOrDefault(s => s.state == state)?.typeName;
        }

        public class VirtualType
        {
            public int virtualType;
            public string typeName;
            public List<StateType> stateTypes;
        }
        public class StateType
        {
            public int state;
            public string typeName;
        }
    }

}
