namespace NetinaShop.Domain.Entities.Products;

public partial class Product
{
    public static Product Create(string persianName, string englishName, string summery, string expertCheck, string tags, string warranty,
        bool beDisplayed,
        double cost, 
        double packingCost,
        bool hasExpressDelivery,
        int stock,
        int maxOrderCount,
        Guid brandId,
        Guid categoryId)
    {
        return new Product(
            persianName, 
            englishName, 
            summery, 
            expertCheck, 
            tags, 
            warranty, 
            beDisplayed,
            cost, 
            packingCost,
            stock,
            hasExpressDelivery,
            maxOrderCount,
            stock > 0,
            brandId,
            categoryId);
    }

    public void AddRate(float rate)
    {
        Rate = ((Rate * ReviewCount) + rate) / (ReviewCount + 1);
        ReviewCount++;
    }

    public void RemoveRate(float rate)
    {

        Rate = ((Rate * ReviewCount) - rate) / (ReviewCount - 1);
        ReviewCount--;
    }

    public ProductStorageFile AddFile(string name, string fileLocation, string fileName, bool isHeader, bool isPrimary, StorageFileType fileType)
    {
        var ent = ProductStorageFile.Create(name, fileLocation, fileName, isHeader, isPrimary, fileType, Id);
        Files.Add(ent);
        return ent;
    }

    public Specification AddSpecification(string title, string detail,string value, bool isFeature, Guid parentId)
    {
        var ent = Specification.Create(title, value, detail, isFeature, Id, parentId);
        Specifications.Add(ent);
        return ent;
    }
}

public partial class ProductStorageFile
{
    public static ProductStorageFile Create(string name, string fileLocation, string fileName, bool isHeader,
        bool isPrimary, StorageFileType fileType, Guid productId)
    {
        return new ProductStorageFile(name, fileLocation, fileName, isHeader, isPrimary, fileType, productId);
    }
}

public partial class Review
{
    public static Review Create(string title, string comment, float rate, bool isBuyer, Guid productId, Guid userId)
    {
        return new Review(title, comment, rate, isBuyer, productId, userId);
    }

    public void ConfirmReview()
        => IsConfirmed = true;
}

public partial class Specification
{
    public static Specification Create(string title,string value, string detail, bool isFeature, Guid productId, Guid parentId)
    {
        return new Specification(title, detail, value, isFeature, productId, parentId);
    }
}