// // src/controllers/discount.controller.ts
// import { Request, Response } from 'express';
// import { getRepository } from 'typeorm';
// import { Discount } from '../entity/discount';
// import { DiscountRequest, DiscountResponse } from '../models/dto/discount';
// import { AppDataSource } from '../data-source';
// // import { authMiddleware } from '../middleware/auth.middleware';

// export class DiscountController {
//   private discountRepository = AppDataSource.getRepository(Discount);

//   async createDiscount(req: Request, res: Response) {
//     try {
//       const discountData: DiscountRequest = req.body;

//       const discount = this.discountRepository.create({
//         ...discountData,
//         start_date: new Date(discountData.start_date),
//         end_date: discountData.end_date ? new Date(discountData.end_date) : undefined
//       });

//       await this.discountRepository.save(discount);

//       const response: DiscountResponse = {
//         ...discount,
//         category_id: discount.category?.category_id,
//         product_id: discount.product?.product_id
//       };

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

//   async getAllDiscounts(req: Request, res: Response) {
//     try {
//       const discounts = await this.discountRepository.find({
//         relations: ['category', 'product']
//       });

//       const response: DiscountResponse[] = discounts.map(discount => ({
//         ...discount,
//         category_id: discount.category?.category_id,
//         product_id: discount.product?.product_id
//       }));

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

//   async applyDiscountToCart(req: Request, res: Response) {
//     try {
//       const { discount_code } = req.body;
//       // Implementation would check discount validity and apply to cart total
//       res.json({ message: 'Discount applied successfully' });
//     } catch (error) {
//       res.status(500).json({ message: 'Error applying discount', error: error.message });
//     }
//   }
// }