using System.Collections.Generic;
using System.Linq;
using Sockeye.Biz;
using Sockeye.Models;

namespace Sockeye.DataList
{
    internal class ProductDataList : DataListProcessingBase
    {
        public ProductDataList(long translationId)
        {
            DefaultListAType = SockType.Product;
            SQLFrom = @"FROM aproduct LEFT JOIN avendor ON (aproduct.vendorid = avendor.id)";

            var RoleSet = BizRoles.GetRoleSet(DefaultListAType);
            AllowedRoles = RoleSet.ReadFullRecord | RoleSet.Change;
            DefaultColumns = new List<string>() { "ProductName", "ProductGroup", "ProductVendorCode", "ProductOurCode" };
            DefaultSortBy = new Dictionary<string, string>() { { "ProductName", "+" } };
            FieldDefinitions = new List<DataListFieldDefinition>();
           
            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "ProductName",
                FieldKey = "ProductName",
                SockType = (int)SockType.Product,
                UiFieldDataType = (int)UiFieldDataType.Text,
                SqlIdColumnName = "aproduct.id",
                SqlValueColumnName = "aproduct.name",
                IsRowId = true
            });

            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "ProductGroup",
                FieldKey = "ProductGroup",
                UiFieldDataType = (int)UiFieldDataType.Enum,
                EnumType = Sockeye.Util.StringUtil.TrimTypeName(typeof(ProductGroup).ToString()),
                SqlValueColumnName = "aproduct.pgroup"
            });

            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "Active",
                FieldKey = "Active",
                UiFieldDataType = (int)UiFieldDataType.Bool,
                SqlValueColumnName = "aproduct.active"
            });

            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "ProductVendorCode",
                FieldKey = "ProductVendorCode",
                UiFieldDataType = (int)UiFieldDataType.Text,
                SqlValueColumnName = "aproduct.vendorcode"
            });

            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "ProductOurCode",
                FieldKey = "ProductOurCode",
                UiFieldDataType = (int)UiFieldDataType.Text,
                SqlValueColumnName = "aproduct.ourcode"
            });

            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "Vendor",
                FieldKey = "Vendor",
                SockType = (int)SockType.Vendor,
                UiFieldDataType = (int)UiFieldDataType.Text,
                SqlIdColumnName = "aproduct.vendorid",
                SqlValueColumnName = "avendor.name"
            });

            FieldDefinitions.Add(new DataListFieldDefinition
            {
                TKey = "Tags",
                FieldKey = "producttags",
                UiFieldDataType = (int)UiFieldDataType.Tags,
                SqlValueColumnName = "aproduct.tags"
            });

        }

    }//eoc
}//eons