using AutoTurnOver.Models;
using Dapper;
using System;
using System.Collections.Generic;
using System.Linq;
using AutoTurnOver.Models.ApiDto;
using AutoTurnOver.Models.Base;
using AutoTurnOver.DB.Base;

namespace AutoTurnOver.DB
{
   public class base_sku_dao : connectionHelper
    {
        public static Page<dc_base_sku> GetPage(dc_base_sku_search_dto search)
        {
            var sql = " select t1.* from dc_base_sku as t1  where 1=1 ";
            DynamicParameters parameters = new DynamicParameters();

            if (!string.IsNullOrWhiteSpace(search.bailun_sku))
            {
                sql += " and t1.bailun_sku = @bailun_sku ";
                parameters.Add("bailun_sku", search.bailun_sku);
            }
            if (!string.IsNullOrWhiteSpace(search.buyer_name))
            {
                sql += " and t1.buyer_name = @buyer_name ";
                parameters.Add("buyer_name", search.buyer_name);
            }
            if (!string.IsNullOrWhiteSpace(search.product_inner_code))
            {
                sql += " and t1.product_inner_code = @product_inner_code ";
                parameters.Add("product_inner_code", search.product_inner_code);
            }
            if (!string.IsNullOrWhiteSpace(search.product_code))
            {
                sql += " and t1.product_code = @product_code ";
                parameters.Add("product_code", search.product_code);
            }
           
            return _connection.Page<dc_base_sku>(sql, search, parameters);
        }
    }
}
