using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Skcks.Study.AbpProject.Categories;
using Skcks.Study.AbpProject.Products;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;

namespace Skcks.Study.AbpProject.Data;

public class AbpProjectDataSeedContributor:IDataSeedContributor,ITransientDependency
{
    private readonly IRepository<Category, Guid> _categoryRepository;
    private readonly IRepository<Product, Guid> _productRepository;

    public AbpProjectDataSeedContributor(IRepository<Category, Guid> categoryRepository, IRepository<Product, Guid> productRepository)
    {
        _categoryRepository = categoryRepository;
        _productRepository = productRepository;
    }

    public async Task SeedAsync(DataSeedContext context)
    {
        if (await _categoryRepository.CountAsync() > 0)
        {
            return;
        }

        var testCategory = new Category
        {
            Name = "Test Category",
        };
        await _categoryRepository.InsertManyAsync(new List<Category> { testCategory});

        var testProduct = new Product
        {
            Category = testCategory,
            Name = "测试商品",
            Price = 99999,
            ReleaseDate = DateTime.Now,
            StockState = ProductStockState.NotAvailable
        };


        await _productRepository.InsertManyAsync(new List<Product> { testProduct });
    }
}