using CMSMicroservice.Protobuf.Protos.Products;
using Grpc.Core;

namespace CMSMicroservice.WebApi.Services;

public class ProductsService : ProductsContract.ProductsContractBase
{
    public override async Task<CreateNewProductsResponse> CreateNewProducts(CreateNewProductsRequest request, ServerCallContext context)
    {
        throw new RpcException(new Status(StatusCode.Unimplemented, "Method not implemented yet"));
    }
    
    public override async Task<Google.Protobuf.WellKnownTypes.Empty> UpdateProducts(UpdateProductsRequest request, ServerCallContext context)
    {
        throw new RpcException(new Status(StatusCode.Unimplemented, "Method not implemented yet"));
    }
    
    public override async Task<Google.Protobuf.WellKnownTypes.Empty> DeleteProducts(DeleteProductsRequest request, ServerCallContext context)
    {
        throw new RpcException(new Status(StatusCode.Unimplemented, "Method not implemented yet"));
    }
    
    public override async Task<GetProductsResponse> GetProducts(GetProductsRequest request, ServerCallContext context)
    {
        throw new RpcException(new Status(StatusCode.Unimplemented, "Method not implemented yet"));
    }
    
    public override async Task<GetAllProductsByFilterResponse> GetAllProductsByFilter(GetAllProductsByFilterRequest request, ServerCallContext context)
    {
        throw new RpcException(new Status(StatusCode.Unimplemented, "Method not implemented yet"));
    }
    
    public override async Task<BulkUpdateProductPricesResponse> BulkUpdateProductPrices(BulkUpdateProductPricesRequest request, ServerCallContext context)
    {
        throw new RpcException(new Status(StatusCode.Unimplemented, "Method not implemented yet"));
    }
    
    public override async Task<BulkUpdateProductStockResponse> BulkUpdateProductStock(BulkUpdateProductStockRequest request, ServerCallContext context)
    {
        throw new RpcException(new Status(StatusCode.Unimplemented, "Method not implemented yet"));
    }
    
    public override async Task<GetLowStockProductsResponse> GetLowStockProducts(GetLowStockProductsRequest request, ServerCallContext context)
    {
        throw new RpcException(new Status(StatusCode.Unimplemented, "Method not implemented yet"));
    }
    
    public override async Task<ToggleProductStatusResponse> ToggleProductStatus(ToggleProductStatusRequest request, ServerCallContext context)
    {
        throw new RpcException(new Status(StatusCode.Unimplemented, "Method not implemented yet"));
    }
    
    // ============= Customer-specific Methods =============
    
    public override async Task<GetProductsResponse> GetCustomerProducts(GetProductsRequest request, ServerCallContext context)
    {
        // For now, return mock response with gallery and categories
        return new GetProductsResponse
        {
            Id = request.Id,
            Title = $"Product {request.Id}",
            Description = "Sample product description for customers",
            ShortInfomation = "Short info",
            FullInformation = "Full product information for customers",
            Price = 50000,
            Discount = 10,
            Rate = 4,
            ImagePath = "/images/product.jpg",
            ThumbnailPath = "/images/product-thumb.jpg",
            SaleCount = 25,
            ViewCount = 150,
            RemainingCount = 10,
            Gallery = 
            {
                new ProductGalleryItem
                {
                    ProductGalleryId = 1,
                    ProductImageId = 1,
                    Title = "Main Image",
                    ImagePath = "/gallery/main.jpg",
                    ImageThumbnailPath = "/gallery/main-thumb.jpg"
                }
            },
            Categories =
            {
                new ProductCategoryPath
                {
                    CategoryId = 1,
                    Title = "Electronics",
                    Path = 
                    {
                        new CategoryNode { Id = 1, Title = "Electronics" }
                    }
                }
            }
        };
    }
    
    public override async Task<GetCustomerProductsByFilterResponse> GetCustomerProductsByFilter(GetAllProductsByFilterRequest request, ServerCallContext context)
    {
        // Mock response for customers with categories
        return new GetCustomerProductsByFilterResponse
        {
            MetaData = new CMSMicroservice.Protobuf.Protos.MetaData
            {
                CurrentPage = 1,
                TotalPage = 1,
                PageSize = 10,
                TotalCount = 2,
                HasPrevious = false,
                HasNext = false
            },
            Models =
            {
                new GetCustomerProductsByFilterResponseModel
                {
                    Id = 1,
                    Title = "Sample Product 1",
                    Description = "Description 1",
                    ShortInfomation = "Short info 1",
                    FullInformation = "Full info 1",
                    Price = 45000,
                    Discount = 5,
                    Rate = 4,
                    ImagePath = "/images/product1.jpg",
                    ThumbnailPath = "/images/product1-thumb.jpg",
                    SaleCount = 15,
                    ViewCount = 120,
                    RemainingCount = 8,
                    Categories = 
                    {
                        new ProductCategoryPath
                        {
                            CategoryId = 1,
                            Title = "Electronics",
                            Path = 
                            {
                                new CategoryNode { Id = 1, Title = "Electronics" }
                            }
                        }
                    }
                },
                new GetCustomerProductsByFilterResponseModel
                {
                    Id = 2,
                    Title = "Sample Product 2", 
                    Description = "Description 2",
                    ShortInfomation = "Short info 2",
                    FullInformation = "Full info 2",
                    Price = 35000,
                    Discount = 15,
                    Rate = 5,
                    ImagePath = "/images/product2.jpg", 
                    ThumbnailPath = "/images/product2-thumb.jpg",
                    SaleCount = 30,
                    ViewCount = 200,
                    RemainingCount = 5,
                    Categories =
                    {
                        new ProductCategoryPath
                        {
                            CategoryId = 2,
                            Title = "Books",
                            Path = 
                            {
                                new CategoryNode { Id = 2, Title = "Books" }
                            }
                        }
                    }
                }
            }
        };
    }
}
