// // src/controllers/product-variant.controller.ts
// import { Request, Response } from 'express';
// import { getRepository } from 'typeorm';
// import { ProductVariant } from '../entity/product-variant';
// import { CreateProductVariantDto, UpdateProductVariantDto, ProductVariantResponseDto } from '../dto/product-variant.dto';

// export class ProductVariantController {
//   private variantRepository = getRepository(ProductVariant);

//   async createVariant(req: Request, res: Response) {
//     try {
//       const variantData: CreateProductVariantDto = req.body;
//       const variant = this.variantRepository.create(variantData);
//       await this.variantRepository.save(variant);

//       const response: ProductVariantResponseDto = {
//         variant_id: variant.variant_id,
//         sku: variant.sku,
//         price: variant.price,
//         stock_quantity: variant.stock_quantity,
//         weight: variant.weight,
//         dimensions: variant.dimensions,
//         color: variant.color,
//         material: variant.material,
//         product_id: variant.product_id
//       };

//       res.status(201).json(response);
//     } catch (error) {
//       res.status(500).json({ message: 'Error creating product variant', error: error.message });
//     }
//   }

//   async getVariantsByProduct(req: Request, res: Response) {
//     try {
//       const productId = parseInt(req.params.productId);
//       const variants = await this.variantRepository.find({
//         where: { product_id: productId },
//         relations: ['product', 'images']
//       });
//       res.json(variants);
//     } catch (error) {
//       res.status(500).json({ message: 'Error fetching product variants', error: error.message });
//     }
//   }

//   async getVariantById(req: Request, res: Response) {
//     try {
//       const variantId = parseInt(req.params.id);
//       const variant = await this.variantRepository.findOne(variantId, {
//         relations: ['product', 'images']
//       });

//       if (!variant) {
//         return res.status(404).json({ message: 'Product variant not found' });
//       }

//       res.json(variant);
//     } catch (error) {
//       res.status(500).json({ message: 'Error fetching product variant', error: error.message });
//     }
//   }

//   async updateVariant(req: Request, res: Response) {
//     try {
//       const variantId = parseInt(req.params.id);
//       const updateData: UpdateProductVariantDto = req.body;

//       await this.variantRepository.update(variantId, updateData);
//       const updatedVariant = await this.variantRepository.findOne(variantId, {
//         relations: ['product']
//       });

//       res.json(updatedVariant);
//     } catch (error) {
//       res.status(500).json({ message: 'Error updating product variant', error: error.message });
//     }
//   }

//   async deleteVariant(req: Request, res: Response) {
//     try {
//       const variantId = parseInt(req.params.id);
//       await this.variantRepository.delete(variantId);
//       res.json({ message: 'Product variant deleted successfully' });
//     } catch (error) {
//       res.status(500).json({ message: 'Error deleting product variant', error: error.message });
//     }
//   }
// }